Help with simple java!!
Hey all, basically im a newbie doin java at the moment...i mean i know a little, but not enough to sit down and work it out (unless i explode)! its crazy, basically all i am trying to do at the moment is to try and write an applet that basically shows 1 label, and 1 text field next to it so the user can input a 3 digit number...i am tryin to put these two simple fields at the top of the applet and in the end i would like a square in the middle of the applet that will change colour corresponsing to what number the user inputs...so far with my little understanding, i have tried to work out as follows:-
import.javax.swing.*;
import.java.awt.*;
import.java.awt.event.*;
public class Ex1 extends JApplet
{
public JLabel label1, label2, label3;
public JTextField text1, text2, text3;
public void init()
{
text1 = new JTextField(3);
text1.addActionListener(this);
text2 = new JTextField(3);
text2.addActionListener(this);
text3 = new JTextField(3);
text3.addActionListener(this);
label1 = new JLabel(" Red ");
label2 = new JLabel(" Green ");
label3 = new JLabel(" Blue ");
Container c = getContentPane();
JPanel labPanel = new JPanel();
labPanel.add(label1);
labPanel.add(label2);
labPanel.add(label3);
labPanel.add(text1);
labPanel.add(text2);
labPanel.add(text3);
c.add(labPanel, BorderLayout.NORTH);
}
}
i know this is no where near complete, but i am stuck and not even sure if this is the correct start, any help would be brilliant and much apprectaed to get me on my way!
Thanks, and regards,
Ben
[1763 byte] By [
benw2007] at [2007-11-20 11:40:17]

# 2 Re: Help with simple java!!
yeah i know...but its not really the fact that i dont know the programming code to do what i need to do, that is fine! its pretty much the understanding of what i need to input, and in what order!
for example...i need to create an init method i assume with the labels and the text fields in, but then what do i need to do!??! i take it i have created the labels and the text fields correctly??
its just the understanding of it all really
regards
# 3 Re: Help with simple java!!
- So did you not understand what I meant when I said use code tags or did you just chose to ignore it? If you didnt understand, then, as a tip, generally, when you ask for help, if theres some part of what the helper is saying that you dont understand ... ask for clarification.
yeah i know...but its not really the fact that i dont know the programming code to do what i need to do, that is fine! its pretty much the understanding of what i need to input, and in what order!
I didnt understand that at all...you know how to program the code but you dont know what to 'input'?? Um...programming code is inputting the code in the text editor...maybe I'm not understanding...define what you mean by 'input'.
To learn how to write applets, read this:
http://java.sun.com/docs/books/tutorial/deployment/applet/index.html
# 4 Re: Help with simple java!!
oh right sorry, no i didn't understand what you meant by the tags...i didn't really mean input...
basically what im tryin to say is, i know how to type the programming code, its just setting the format out, understand what goes where! i know i have to create an init method-i then need to create the labels-then i need to create the text fields- but then im just unsure!?
thats what im asking if someone can help me with, just some knowledge on what i actually need to do, and in what order!?
regards
# 5 Re: Help with simple java!!
oh right sorry, no i didn't understand what you meant by the tags...i didn't really mean input...
Code tags make it easier to read code that you post, so things like indentation gets preserved. You can use the 'code' button thats at the top of the area where you type your post in, or you can just put (CODE) your code (/CODE) -- but replace the parentheses with brackets. You can edit your post to correct this. I may not have explained this well, if you still dont understand let me know.
basically what im tryin to say is, i know how to type the programming code, its just setting the format out, understand what goes where!
I'm sure you dont mean it this way, but it sounds to me like you're saying 'I know how to use the keyboard to write text, just not how to make that text be a working program'.
i know i have to create an init method-i then need to create the labels-then i need to create the text fields- but then im just unsure!?
The link I provided to the applet tutorial will explain it better than a forum post can.