BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Please help a student with simple GUI problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE
View previous topic :: View next topic  
Author Message
Double Dragon
Guest





PostPosted: Wed May 05, 2004 6:50 pm    Post subject: Please help a student with simple GUI problem Reply with 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





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;
}
}



Back to top
Mike Mormando
Guest





PostPosted: Wed May 05, 2004 7:38 pm    Post subject: Re: Please help a student with simple GUI problem Reply with quote




"Double Dragon" <mdoubledragon (AT) hotmail (DOT) com> wrote

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



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.