Samiullah Aazam

Greenhorn
+ Follow
since Jul 02, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Samiullah Aazam

Hi JavaRanchers!
I am displaying user texts in a canvas oe below the other.
i have added a button above the canvas. Now, i want that whenever this button gets clicked, one message in the canvas should be moved downward(or disappeared).
Can anybody send some sample code to show this mechanism.
I am desperately looking for it.
ThankX!!!
Samiullah Aazam
21 years ago
I am displaying some messages in a canvas . Now i want these
messages to be scrolled when i move the slider of the adjacent scrollbar(vertical). how can i do that?
I am desperately looking for its solution. Plz. help me.
I hope some of u can certainly do it. I especially request Mr. Manfred to solve it who has helped me earlier.
here is my code:
------------------------------------------------------------
--------------extended canvas class-------------------------
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
class apltcnv extends Canvas
{
int startCan;
int endCan;
Vector msg=new Vector(17);
public apltcnv()
{}
public void paint( Graphics g )
{
Dimension dd = getSize();
double w = dd.getWidth();
double h = dd.getHeight();

System.out.println( "canvas' width= " + w + "canvas' height= " + h+" time****" );
setBackground( Color.cyan );


String str=aplt.tf.getText();
str=str.trim();
if(str.equals("") | | str==null) return;
System.out.println( "b4 addmessage" );
addMessage("sami : "+str);

int ii=msg.size();
System.out.println("vector size "+ii);
g.setColor(Color.red);
displayMessages(g);
aplt.tf.setText("");
}
void addMessage(String str)
{
msg.addElement(str);
}
void displayMessages(Graphics g)
{
Dimension dd=this.getSize();

double h=dd.getHeight();

int ii=msg.size();
startCan=ii;
endCan=0;
System.out.println("startcan "+startCan+" endcan "+endCan);
if(ii>17)
{
startCan=ii;
endCan=ii-16;
System.out.println("startcan "+startCan+" endcan "+endCan);
}
finalDisplay(startCan,endCan,h,g);
}

void finalDisplay(int startCan, int endCan, double h, Graphics g)
{
int rr=startCan-1;
for(;startCan>endCan;endCan++)
{
int ii=msg.size();

String ss=(String)msg.elementAt(rr);

rr=rr-1;

g.drawString(ss,0,(int)h);
h=h-10;
}
}

}
----------------------------------------------------------------
-------------------extended applet class------------------------
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="aplt.class" width=300 height=300>
</applet>
*/
public class aplt extends Applet implements ActionListener
{
Label l;
Button b1,b2;
Panel p,pl,pll;
apltcnv c;
Scrollbar vrt;
public static TextField tf;
public void init()
{
GridBagConstraints gbc = new GridBagConstraints();
setLayout( new BorderLayout() );
setBackground( Color.yellow );
l=new Label("chat applet");
pl=new Panel();
pl.setLayout(new GridLayout(2,1,5,5));
pl.add(l);
pll=new Panel();
pll.setLayout(new FlowLayout());
b1 = new Button( "btn1" );
b2 = new Button( "btn2" );
pll.add(b1);
pll.add(b2);
pl.add(pll);

add( pl, BorderLayout.NORTH );
p = new Panel( new GridBagLayout() );
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.CENTER;
c = new apltcnv();
c.setSize( 280, 170 );
p.add( c, gbc );

// p.add("East",vrt);
add( p, BorderLayout.CENTER );
vrt=new Scrollbar(Scrollbar.VERTICAL,1,2,1,250);
add(vrt,BorderLayout.EAST);
tf=new TextField(20);
add(tf,BorderLayout.SOUTH);
tf.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object oo=e.getSource();
if(oo==tf)
{
String getMsg=tf.getText();
getMsg=getMsg.trim();
if(getMsg.equals("") | | getMsg==null) return;
c.repaint();
}

}
public void paint( Graphics g )
{



}
}
21 years ago
Hello Manfred!
I have read the GridBagLayout from some books but still unable to get the full grasp over this. Will u please tell me about some good sites(or internet resources) where i can get a nicely explained(with support of diagrams) deatails of GridBagLayout manager.
Hope to get a positive reply from your end.
Thankx! Bye!!!1
Samiullah Aazam
21 years ago
Hello Manfred,
I am really very thankful to u for giving your precious time to solve my problem. Your approach really encouraged me to play with the canvas as per my requirement and understood that why GridBagLayout is more versatile that any other Layouts. Actually, i am working on a chat applet project & this was just the first step to understand the canvas in which later on i would like to place user messages one below the previous in the canvas. Now i can cofidently move towards my project. If any problem comes out in its development then i'll contact u without any hesitation . Hope u will help me in future too.
Thankx a lot! Bye!
samiullah Aazam
21 years ago
Here is an applet(code) which has the following settings:

Layout for the applet is BorderLayout.
Background color for the applet is yellow.
A button(b1) is added to the "north" of the applet.
A panel(p) is added to the "center" of the applet.
Layout for the Panel(p) is GridLayout(1,1,5,5).
A canvas(canvas11) is added to the panel(p).
Background color for the canvas is cyan.
I chose the size of the canvas to b (100,50) pixels.

When i run this applet with appletviewer it firstly shows(flicks) the applet's background color as yellow & the statically showing its background color as cyan. i am unable to figure out that why do this canvas is covering the entire area of the applet although its size is specified. I just want to create a canvas(with red color) of a specified size say 100,100 pixels & place this canvas at the center of an applet(with BorderLayout) of size (width=300, height=300). This canvas should not cover the entire area of the applet. How can i do that? Plz. help me!
Hope some of u will clear my doubt.
Thankx!
the code of the applet is:
--------------------------------------------------------------
import java.awt.*;
import java.applet.*;

/*
<applet code = "vc.class" width = 350 height = 300>
</applet>
*/
public class vc extends Applet
{
Button b1=new Button("button");
Panel p=new Panel();
canv1 canv11=new canv1();
public void init()
{
setLayout( new BorderLayout() );
p.setLayout( new GridLayout(1,1,5,5) );
canv11.setBackground( Color.yellow );
p.add(canv11);
add("Center",p);
add("North",b1);

}
}
class canv1 extends Canvas
{
public void paint(Graphics g)
{
Dimension dd=this.getSize();
double w=dd.getWidth();
double h=dd.getHeight();
setBackground( Color.cyan );
g.drawString("hi",10,25);
System.out.println("width= "+w+"height= "+h);
}
public Dimension minimumSize()
{
return new Dimension(100,50);
}
public Dimension preferredSize()
{
return minimumSize();
}
}
21 years ago
Hi all!,
Can anybody send me the code of a chat applet where user messages entered via tex field are displayed at the bottom of a canvas.Older messages should be placed at the above the newer messages. Its urgent. Hope anybody will help me soon.
Thankx!!!
21 years ago
Hello everybody!
Here is an applet java file which displays the user texts(entered via text field) in its upper text area. Now i wnat this text area to be replaced by a canvas and this canvas must contain a scrollbar.
If anyone of u could be able to that then plz. mention your code at this forum or mail me at
amu_guy@hotmail.com
Its vrey urgent.
Thankx!
----------------------------------------------------------------
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="dd1.java" width=400 height=400>
</applet>
*/
public class dd1 extends Applet implements
ActionListener,ItemListener{
TextArea textarea1;
TextField text1;
Button button1;
Panel down,down1;
Label l=new Label("Applet for Fonts & Colors");
Choice ch1=new Choice();
Choice ch2=new Choice();
Choice ch3=new Choice();


public void init(){

down=new Panel();
down.setLayout(new BorderLayout());
this.setLayout(new BorderLayout());
down1=new Panel();

add("North",l);

textarea1=new TextArea("",5,20,1);
add("Center",textarea1);

text1=new TextField(50);
down.add("North",text1);
text1.addActionListener(this);

button1=new Button("Click Me");
down.add("South",down1);
button1.addActionListener(this);

down1.add("North", button1);
add("South", down);
down1.setLayout(new GridLayout(1,3));
ch1.add("Select a font type");
ch2.add("Select a font style");
ch3.add("Select a font size");
ch1.add("SansSerif");
ch1.add("Serif");
ch1.add("Monospaced");
ch2.add("PLAIN");
ch2.add("BOLD");
ch2.add("ITALIC");

ch3.add("25");
ch3.add("30");
ch3.add("40");
ch1.addItemListener(this);
ch2.addItemListener(this);
ch3.addItemListener(this);
down1.add("South",ch1);
down1.add("West",ch2);
down1.add("East",ch3);
}

public void actionPerformed(ActionEvent e)
{

if(e.getSource()==button1){

String gg=text1.getText();
textarea1.append(gg);
text1.setText("");
}
else if(e.getSource()==text1)
{
String gg=text1.getText();
textarea1.append(gg);
text1.setText("");
}
}
public void itemStateChanged(ItemEvent e1)
{
if(e1.getSource()==ch1)
{
int a=0;
String ss=ch2.getSelectedItem();
ss=ss.trim();

if(ss.equals("BOLD")) a=Font.BOLD;
if(ss.equals("PLAIN")) a=Font.PLAIN;
if(ss.equals("ITALIC")) a=Font.ITALIC;

int aa=Integer.parseInt(ch3.getSelectedItem());
Font f=new Font(ch1.getSelectedItem(),a,aa);
textarea1.setFont(f);

}
}
}
21 years ago