Just a small problem
Well i'm still on my quest to learn java and so for yet another test of my skills thus far, I came up with this program. The only thing that is left is that I can't get my program to take the diameter and color the user enters and draw a circle with it!?! Haha its driving me crazy!? Can anyone help? Here is my code down below
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
public class CircleGUI implements ActionListener
{
JLabel diameterLabel = new JLabel("Diameter");
JLabel colorLabel = new JLabel("Color");
JTextField diameterField = new JTextField(4); //text field for firstname
JTextField colorField = new JTextField(10); //text field for lastname
JTextArea bothArea = new JTextArea(15,30); //text area for bothnames
JButton button1 = new JButton("Draw");
JPanel panel = new JPanel();
JFrame frame = new JFrame("Address"); //frame for window
public CircleGUI()
{
panel.add(diameterLabel);
panel.add(diameterField); //add text field to panel
panel.add(colorLabel);
panel.add(colorField);
panel.add(bothArea);
button1.addActionListener(this); //add a click listener tobutton
panel.add(button1); //add another label to panel
frame.setContentPane(panel); //set panel as frame's content
frame.setSize(200, 200); //set frame size (width,height)
frame.setVisible(true); //make frame visible
}//end FrameExample()
public void actionPerformed(ActionEvent e)
{
if (e.getSource().equals("draw")) {
String command = e.getActionCommand();
String a = diameterField.getText();
String b = colorField.getText();
lblOutput.setText(drawCircle(diameterField.getText(),colorField.getText()));
}//end actionPerformed()
}
}//end FrameExample
[1926 byte] By [
NaokoLovea] at [2007-10-2 21:07:01]

Hi, Naokolove,
If you have format your code with "", I bet you will get your answer much earlier...
here are several obvious problems in your code.
after
JButton button1 = new JButton("Draw");
You need add
button1.addActionListener(this);
> Hi, Naokolove,
>
> If you have format your code with "", I
> bet you will get your answer much earlier...
You mean between [code][/code] tags?
> here are several obvious problems in your code.
> after
> JButton button1 = new JButton("Draw");
>
> You need add
> button1.addActionListener(this);
The OP added an ActionListener to the button in the constructor. Any other ideas happymustang?
hi, prometheuzz, You cauth me on this one :). I'll update my answer asap
Hi, Naokolove,
Can you also post your drawCircle() method?
Currently, what you called is
drawCircle(String diameter, String color)
Are you sure that is what you declared in your code?
You may need cast String into integer if your code is
drawCircle(int diameter, int color)
Using Integer.parseInt(stringinput)
@OP:
There are a lot of things wrong with your code. I adjusted a couple of things in it in such a way that it will compile, run and will show a GUI:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CircleGUI extends JFrame implements ActionListener {
JLabel diameterLabel = new JLabel("Diameter");
JLabel colorLabel = new JLabel("Color");
JTextField diameterField = new JTextField(4); //text field for firstname
JTextField colorField = new JTextField(10); //text field for lastname
JTextArea bothArea = new JTextArea(15,30); //text area for bothnames
JButton button1 = new JButton("Draw");
JPanel panel = new JPanel();
JFrame frame = new JFrame("Address"); //frame for window
public CircleGUI() {
panel.add(diameterLabel);
panel.add(diameterField); //add text field to panel
panel.add(colorLabel);
panel.add(colorField);
panel.add(bothArea);
button1.addActionListener(this); //add a click listener tobutton
panel.add(button1); //add another label to panel
frame.setContentPane(panel); //set panel as frame's content
frame.setSize(400, 350); //set frame size (width,height)
frame.setVisible(true); //make frame visible
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
String command = e.getActionCommand();
String a = diameterField.getText();
String b = colorField.getText();
bothArea.setText("Button pushed...");
// The variable 'lblOutput' is not declared anywhere
// that drawCircle is also a mysterious method
//lblOutput.setText(drawCircle(diameterField.getText(),colorField.getText()));
}
}
public static void main(String[] args) {
new CircleGUI();
}
}
But you are in desperate need of a decent Swing tutorial.
Here's a good one: http://java.sun.com/docs/books/tutorial/uiswing/
Good luck.
> You may need cast String into integer if your code is> > drawCircle(int diameter, int color)> > Using Integer.parseInt(stringinput)That's not casting. You can't cast a String to an int.
jverda at 2007-7-13 23:52:35 >

jverd is correct.. should be parsing.. sorry..
jverg is a much nicer helper :). I was thinking to help format the code but did find a good tool in the computer i used.
> jverg is a much nicer helper :). Just out of curiosity: how do you come to this conclusion?> I was thinking to help format the code but did find a> good tool in the computer i used.What do you mean?
hoho.. prometheuzz,
don't be too sensitvie .. I mean jverd is a much nicer and more patient helper than me (not compare to you :). Actually, I knew you usually are nice to askers (that's why I only have taken defense posts but no offense post)..
for 2.
I want to say:
I was thinking to help the asker format his code. But the computer I am using is not my programming computer. It does not have any java programming editor on it. And I am lazy to use Notepad to reformat it.
Buddy, I surrender..
> hoho.. prometheuzz,
> don't be too sensitvie .. I mean jverd is a much
> nicer and more patient helper than me (not compare to
> you :). Actually, I knew you usually are nice to
> askers (that's why I only have taken defense posts
> but no offense post)..
I wasn't being sensitive, I was just wondering how you came to the conclusion that jverd was (or is) nicer and more patient than someone else by the one reply of him in this thread.
> for 2.
> I want to say:
>
> I was thinking to help the asker format his code. But
> the computer I am using is not my programming
> computer. It does not have any java programming
> editor on it. And I am lazy to use Notepad to
> reformat it.
>
> Buddy, I surrender..
No need to surrender, I just didn't understand you, that's why I asked.