Board index » jbuilder » Please help a student with simple GUI problem

Please help a student with simple GUI problem


2004-05-06 02:50:03 AM
jbuilder1
i donno why this isnt working when i try to create only a point (not
circkle) filling the first two fields only. I figured out finally that the
JTextField "radius" is not returning radius.getText( )= =""
i donno why...please read this simple program and help me. Thanks in
advance...Double Dragon
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class inherit extends JFrame implements ActionListener
{
JTextField x,y,radius;
JButton create;
JTextArea result;
JScrollPane scroll;
inherit()
{
super("Inheritance Demo");
setSize(300,300);
setVisible(true);
Container c=getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER));
x=new JTextField(5);
x.addActionListener(this);
c.add(x);
x.setToolTipText("Enter X Co-ordinate Here");
x.requestFocus();
x.setVisible(true);
y=new JTextField(5);
y.addActionListener(this);
c.add(y);
y.setToolTipText("Enter Y Co-ordinate Here");
y.setVisible(true);
radius=new JTextField(5);
radius.addActionListener(this);
c.add(radius);
radius.setToolTipText("Enter Radius If Creating A Circle");
create=new JButton("Create");
create.addActionListener(this);
c.add(create);
create.setToolTipText("Click To Create Object");
result=new JTextArea(10,20);
result.setText("Results Will Be Displayed Here");
result.setEditable(false);
scroll=new JScrollPane(result);
c.add(scroll);
}
public void actionPerformed(ActionEvent e)
{
boolean a[]=new boolean[3];
if (x.getText()!="")
{
a[0]=true;
}
if (y.getText()!="")
{
a[1]=true;
}
if (radius.getText()!="")
{
a[2]=true;
}
if (a[0]==true && a[1]==true)
{
if (a[2]==true)
{
circle c=new
circle(Integer.parseInt(x.getText()),Integer.parseInt(y.getText()),Integer.p
arseInt(radius.getText()));
result.setText(c.output);
}
else
{
point p=new
point(Integer.parseInt(x.getText()),Integer.parseInt(y.getText()));
result.setText(p.output);
}
}
else
{
result.setText("Insufficient Values Entered For Successful Creation
Of Objects");
}
}
public static void main(String args[])
{
inherit i=new inherit();
i.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class point
{
private int x,y;
public static String output;
point()
{
x=y=0;
}
point(int a,int b)
{
x=a;
y=b;
output="Point A("+x+","+y+") Created";
}
protected int getx()
{
return x;
}
protected int gety()
{
return y;
}
}
class circle extends point
{
private int radius;
circle()
{
radius=0;
}
circle(int a)
{
radius=a;
}
circle(int a,int b,int c)
{
super(a,b);
output+="\n Circle With Radius "+c+" Created";
radius=c;
}
}
 
 

Re:Please help a student with simple GUI problem

"Double Dragon" < XXXX@XXXXX.COM >wrote in message
Quote
i donno why this isnt working when i try to create only a point (not
circkle) filling the first two fields only. I figured out finally that the
JTextField "radius" is not returning radius.getText( )= =""
i donno why...please read this simple program and help me. Thanks in
advance...Double Dragon
== doesn't work for string comparison,
you have to use mystring.equals("String to compare to")
Mike