| | |
doing a program blinded
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2008
Posts: 189
Reputation:
Solved Threads: 0
Ezzarel you dont havta reply to this prolly think I am the biggest idiot living but I still am having problems with this program...I tried movin a bench of stuff around but just went back to this w\some minor changes and still havin problems
java Syntax (Toggle Plain Text)
//packages to import import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Checkerboard extends Frame implements ActionListener { private Panel topPanel; private TextArea topDisplay[]; private Panel bottomPanel; private TextField startField = new TextField(10); private TextField stopField = new TextField(10); private TextField stepField = new TextField(10); private Label startLabel = new Label ("Start"); private Label stopLabel = new Label ("Stop"); private Label stepLabel = new Label ("Step"); private Button goButton[]; private Button clearButton[]; private boolean clearText; private boolean first; private int start; private int stop; private int step; //constructor methods public Checkerboard() { //set layouts for the Frame and Panels setLayout(new BorderLayout()); topPanel.setLayout(new GridLayout(4, 4, 10, 10)); bottomPanel.setLayout(new GridLayout(3, 3, 5, 5)); //construct components and initialize beginning values topPanel = new Panel(); topDisplay = new TextArea[16]; first = true; bottomPanel = new Panel(); int start = 0; int stop = 0; int step = 0; bottomPanel.add(startField); bottomPanel.add(stopField); bottomPanel.add(stepField); bottomPanel.add(startLabel); bottomPanel.add(stopLabel); bottomPanel.add(stepLabel); clearText = true; //construct the Display for(int i = 1; i <= 16; i++) { topDisplay[i] = new TextArea(null,3,5,3); } //add components to frame add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.CENTER); //set color to the panel //row 1 for(int i = 1; i <= 4; i++) //set color for setBackground(Color.white); //row 2 for(int i = 5; i <= 8; i++) //set color for setBackground(Color.white); //row 3 for(int i = 9; i <= 12; i++) //set color for setBackground(Color.white); //row 4 for(int i = 13; i <= 16; i++) //set color for setBackground(Color.white); //register the listener with each Button for(int i = 0; i < goButton.length; i++) goButton[i].addActionListener(this); for(int i = 0; i < clearButton.length; i++) clearButton[i].addActionListener(this); //allow the x to close the application addWindowListener(new WindowAdapter() { public void windowclosing(WindowEvent e) { System.exit(0); } } //end window adapter ); } public static void main(String args[]) { Checkerboard f = new Checkerboard(); f.setTitle("Checkerboard Array"); f.setBounds(50, 100, 300, 400); f.setLocationRelativeTo(null); f.setVisible(true); } //end main public void actionPerformed(ActionEvent e) { //test clear String arg = e.getActionCommand(); //clear button was clicked if(arg.equals("Clear")) { clearText = true; start = 0; stop = 0; step = 0; first = true; setBackground(Color.white); startField.requestFocus(); } //end the if clear }//end action listener }//end class
you really think that insulting people who try to help you is going to make them more likely to do your homework for you?
If so, think again...
Or don't you think at all before posting such crap?
If so, think again...
Or don't you think at all before posting such crap?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
First of all, can someone explain to me what he said?:
Because my English are not that good
And it seems to me that Ezzarel has told you the solution. If you don't understand it then learn basic java and don't stuff like gui
•
•
•
•
Ezzarel you dont havta reply to this prolly think I am the biggest idiot living but I still am having problems with this program...I tried movin a bench of stuff around but just went back to this w\some minor changes and still havin problems
And it seems to me that Ezzarel has told you the solution. If you don't understand it then learn basic java and don't stuff like gui
Check out my New Bike at my Public Profile at the "About Me" tab
idiot kid is too lazy to do its own homework and wants us to do it for it.
That and/or it's utterly incapable of understanding what it's being told.
I vote for both of those at the same time.
That and/or it's utterly incapable of understanding what it's being told.
I vote for both of those at the same time.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Jan 2008
Posts: 189
Reputation:
Solved Threads: 0
keep your whining to yourself. Look I even talked with him about it and I was not calling him an idiot. He already helped me and I clearly said anyone but him only because I did not want to keep bothering him since he had done such a great job explaining my errors to me.
I think I made the correct changes by moving things around and initializing the buttons and panels (as long as I did it correctly) and getting a new message that I think has something to do with the TextArea. If this is just something with the action event then I am not worried about it because I am programming that today but if I am still messing something up with initialization point any ideas would be helpful.
Error in the console application says:
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:625)
at java.awt.Container.add(Container.java:307)
at Checkerboard.<init>(Checkerboard.java:52)
at Checkerboard.main(Checkerboard.java:110)
Press any key to continue . . .
Could importing another java package resolve this
I think I made the correct changes by moving things around and initializing the buttons and panels (as long as I did it correctly) and getting a new message that I think has something to do with the TextArea. If this is just something with the action event then I am not worried about it because I am programming that today but if I am still messing something up with initialization point any ideas would be helpful.
java Syntax (Toggle Plain Text)
//packages to import import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Checkerboard extends Frame implements ActionListener { private Panel topPanel; private TextArea topDisplay[]; private Panel bottomPanel; private TextField startField = new TextField(10); private TextField stopField = new TextField(10); private TextField stepField = new TextField(10); private Label startLabel = new Label ("Start"); private Label stopLabel = new Label ("Stop"); private Label stepLabel = new Label ("Step"); private Button goButton; private Button clearButton; private boolean clearText; private boolean first; private int start; private int stop; private int step; //constructor methods public Checkerboard() { //construct components and initialize beginning values topPanel = new Panel(); topDisplay = new TextArea[16]; first = true; bottomPanel = new Panel(); int start = 0; int stop = 0; int step = 0; bottomPanel.add(startField); bottomPanel.add(stopField); bottomPanel.add(stepField); bottomPanel.add(startLabel); bottomPanel.add(stopLabel); bottomPanel.add(stepLabel); bottomPanel.add(goButton); goButton.addActionListener(this); bottomPanel.add(clearButton); clearButton.addActionListener(this); clearText = true; //construct the Display for(int i = 1; i <= 16; i++) { topDisplay[i] = new TextArea(null,3,5,3); } //set layouts for the Frame and Panels setLayout(new BorderLayout()); topPanel.setLayout(new GridLayout(4, 4, 10, 10)); bottomPanel.setLayout(new GridLayout(3, 3, 5, 5)); //add components to frame add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.CENTER); //set color to the panel //row 1 for(int i = 1; i <= 4; i++) //set color for setBackground(Color.white); //row 2 for(int i = 5; i <= 8; i++) //set color for setBackground(Color.white); //row 3 for(int i = 9; i <= 12; i++) //set color for setBackground(Color.white); //row 4 for(int i = 13; i <= 16; i++) //set color for setBackground(Color.white); //allow the x to close the application addWindowListener(new WindowAdapter() { public void windowclosing(WindowEvent e) { System.exit(0); } } //end window adapter ); } public static void main(String args[]) { Checkerboard f = new Checkerboard(); f.setTitle("Checkerboard Array"); f.setBounds(50, 100, 300, 400); f.setLocationRelativeTo(null); f.setVisible(true); } //end main public void actionPerformed(ActionEvent e) { //test clear String arg = e.getActionCommand(); //clear button was clicked if(arg.equals("Clear")) { clearText = true; start = 0; stop = 0; step = 0; first = true; setBackground(Color.white); startField.requestFocus(); } //end the if clear }//end action listener }//end class
Error in the console application says:
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:625)
at java.awt.Container.add(Container.java:307)
at Checkerboard.<init>(Checkerboard.java:52)
at Checkerboard.main(Checkerboard.java:110)
Press any key to continue . . .
Could importing another java package resolve this
bottomPanel.add(goButton);
Where do you do: goButton = new Button("some name"); ? If you don't do this then goButton is null.
Obviously you must initialize everything before you use it. And the compiler will tell you the lines where you try to use null objects
Where do you do: goButton = new Button("some name"); ? If you don't do this then goButton is null.
Obviously you must initialize everything before you use it. And the compiler will tell you the lines where you try to use null objects
Check out my New Bike at my Public Profile at the "About Me" tab
so the lazy idiot kid has fallen into the normal pattern of the homework kiddo and started getting abusive.
How surprising, NOT.
You're going to make a lot of friends with that attitude, kiddo. It's really going to help you bully your way into friendships.
How surprising, NOT.
You're going to make a lot of friends with that attitude, kiddo. It's really going to help you bully your way into friendships.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Jan 2008
Posts: 189
Reputation:
Solved Threads: 0
Ok I just wanna apologize to anyone I offended even the guy from the netherlands. I am not asking for someone to do my homework. These programming classes are the last 2 I have...one is java and the other is C++. I do not want to go into programming because I will be the first to admit I am completely horrible at it. I also do not want it to be called lazy because lazy is not caring and wanting someone to do it for me word for word and I do not want that. I have been working on this program all week and to me a forum is the last resolution for me if I am unable to resolve a problem because you guys especially in this forum have been really helpful for me to understand the material even the guy from the Netherlands.
With that being said I think I have gotten really close because I have gotten my program to run...the only problem is I only can see 3 boxes (they are not even numbered), 3 labels (start, stop,and step), and two giant sized buttons(go and clear)
I really hope this is just something small and could easily be corrected but does anyone see the error I am making in my program. I wanna think it has something to do with my program being out of order but I tried moving a bunch of things around and couldnt come across any changes.
With that being said I think I have gotten really close because I have gotten my program to run...the only problem is I only can see 3 boxes (they are not even numbered), 3 labels (start, stop,and step), and two giant sized buttons(go and clear)
I really hope this is just something small and could easily be corrected but does anyone see the error I am making in my program. I wanna think it has something to do with my program being out of order but I tried moving a bunch of things around and couldnt come across any changes.
java Syntax (Toggle Plain Text)
//packages to import import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Checkerboard extends Frame implements ActionListener { private Panel topPanel; private TextArea topDisplay[]; private Panel bottomPanel; private TextField startField = new TextField(10); private TextField stopField = new TextField(10); private TextField stepField = new TextField(10); private Label startLabel = new Label ("Start"); private Label stopLabel = new Label ("Stop"); private Label stepLabel = new Label ("Step"); private Button goButton; private Button clearButton; private boolean clearText; private boolean first; private int start; private int stop; private int step; //constructor methods public Checkerboard() { //construct components and initialize beginning values topPanel = new Panel(); topDisplay = new TextArea[16]; goButton = new Button("Go"); clearButton = new Button("Clear"); first = true; bottomPanel = new Panel(); int start = 0; int stop = 0; int step = 0; bottomPanel.add(startField); bottomPanel.add(stopField); bottomPanel.add(stepField); bottomPanel.add(startLabel); bottomPanel.add(stopLabel); bottomPanel.add(stepLabel); bottomPanel.add(goButton); goButton.addActionListener(this); bottomPanel.add(clearButton); clearButton.addActionListener(this); clearText = true; //set layouts for the Frame and Panels setLayout(new BorderLayout()); topPanel.setLayout(new GridLayout(4, 4, 10, 10)); bottomPanel.setLayout(new GridLayout(3, 3, 5, 5)); //construct the Display for(int i = 1; i <= 15; i++) { topDisplay[i] = new TextArea(null, 3, 5, 3); //set color to the panel //row 1 for(int x = 1; x <= 4; x++) //set color for setBackground(Color.white); //row 2 for(int x = 5; x <= 8; x++) //set color for setBackground(Color.white); //row 3 for(int x = 9; x <= 12; x++) //set color for setBackground(Color.white); //row 4 for(int x = 13; x <= 16; x++) //set color for setBackground(Color.white); } //add components to frame add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.CENTER); //allow the x to close the application addWindowListener(new WindowAdapter() { public void windowclosing(WindowEvent e) { System.exit(0); } } //end window adapter ); } public static void main(String args[]) { Checkerboard f = new Checkerboard(); f.setTitle("Checkerboard Array"); f.setBounds(50, 100, 300, 400); f.setLocationRelativeTo(null); f.setVisible(true); } //end main public void actionPerformed(ActionEvent e) { //convert data in TextField to int int start = Integer.parseInt(startField.getText()); int stop = Integer.parseInt(stopField.getText()); int step = Integer.parseInt(stepField.getText()); //test clear String arg = e.getActionCommand(); //clear button was clicked if(arg.equals("Clear")) { clearText = true; start = 0; stop = 0; step = 0; first = true; setBackground(Color.white); startField.requestFocus(); } //end the if clear }//end action listener }//end class
•
•
Join Date: Jan 2008
Posts: 189
Reputation:
Solved Threads: 0
FINALLY got what I needed to be done today now just working on the action...was wondering if anyone had a chance to take a look at what I have done so far to make sure everything looks good and was also wanting to know if anyone had an idea on how to put numbers on the boxes...
java Syntax (Toggle Plain Text)
//packages to import import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Checkerboard extends Frame implements ActionListener { private Panel topPanel; private TextArea topDisplay[]; private Panel bottomPanel; private TextField startField = new TextField(10); private TextField stopField = new TextField(10); private TextField stepField = new TextField(10); private Label startLabel = new Label ("Start"); private Label stopLabel = new Label ("Stop"); private Label stepLabel = new Label ("Step"); private Button goButton; private Button clearButton; private boolean clearText; private boolean first; private int start; private int stop; private int step; //constructor methods public Checkerboard() { //construct components and initialize beginning values topPanel = new Panel(); topDisplay = new TextArea[16]; goButton = new Button("Go"); clearButton = new Button("Clear"); first = true; bottomPanel = new Panel(); int start = 0; int stop = 0; int step = 0; bottomPanel.add(startField); bottomPanel.add(stopField); bottomPanel.add(stepField); bottomPanel.add(startLabel); bottomPanel.add(stopLabel); bottomPanel.add(stepLabel); bottomPanel.add(goButton); goButton.addActionListener(this); bottomPanel.add(clearButton); clearButton.addActionListener(this); clearText = true; //set layouts for the Frame and Panels setLayout(new BorderLayout()); topPanel.setLayout(new GridLayout(4, 4, 10, 10)); bottomPanel.setLayout(new GridLayout(3, 3, 5, 5)); //construct the Display for(int i = 0; i <= 15; i++) { topDisplay[i] = new TextArea(null, 3, 5, 3); topPanel.add(topDisplay[i]); //set color to the panel //row 1 for(int x = 1; x <= 4; x++) //set color for setBackground(Color.white); //row 2 for(int x = 5; x <= 8; x++) //set color for setBackground(Color.white); //row 3 for(int x = 9; x <= 12; x++) //set color for setBackground(Color.white); //row 4 for(int x = 13; x <= 16; x++) //set color for setBackground(Color.white); } //add components to frame add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.CENTER); //allow the x to close the application addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } //end window adapter ); } public static void main(String args[]) { Checkerboard f = new Checkerboard(); f.setTitle("Checkerboard Array"); f.setBounds(50, 100, 300, 400); f.setLocationRelativeTo(null); f.setVisible(true); } //end main public void actionPerformed(ActionEvent e) { //convert data in TextField to int int start = Integer.parseInt(startField.getText()); int stop = Integer.parseInt(stopField.getText()); int step = Integer.parseInt(stepField.getText()); for(int i = 1; i <=16; i++) setBackground(Color.blue); for(int i = start; i <= stop; i++) setBackground(Color.yellow); //test clear String arg = e.getActionCommand(); //clear button was clicked if(arg.equals("Clear")) { clearText = true; startField.setText(""); stopField.setText(""); stepField.setText(""); first = true; setBackground(Color.white); startField.requestFocus(); } //end the if clear }//end action listener }//end class
•
•
Join Date: Jan 2008
Posts: 189
Reputation:
Solved Threads: 0
apologize for bothering you guys but I have one more question and no more bothering I promise...
It has to do with my go button...When I click it, the background turns to blue that is no problem but the issue is certain parts do not return to yellow...It is hard to explain withpout showing the instuctions so here are the instructions for the for loop
write another loop that’s based on the user inputs. Each time the loop is executed, change the background color to yellow (so… start your loop at the user’s specified starting condition. You’ll stop at the user’s specified stopping value. You’ll change the fields to yellow every time you increment your loop based on the step value. REMEMBER: Your displayed values are 1 off from your index numbers!!)
In the start stop and step fields in the example I have on my word document there shows 16 boxes looking like this
1 2 3 4
5 6 7 9
9 10 11 12
13 14 15 16
When I input 3 for start 15 for stop and 4 for step the boxes that are to be yellow are 3, 7, 11, 15...however they are all turning blue and was wondering if anyone could take a look at my loop and let me know if I am doing something wrong in it or something else.
It has to do with my go button...When I click it, the background turns to blue that is no problem but the issue is certain parts do not return to yellow...It is hard to explain withpout showing the instuctions so here are the instructions for the for loop
write another loop that’s based on the user inputs. Each time the loop is executed, change the background color to yellow (so… start your loop at the user’s specified starting condition. You’ll stop at the user’s specified stopping value. You’ll change the fields to yellow every time you increment your loop based on the step value. REMEMBER: Your displayed values are 1 off from your index numbers!!)
In the start stop and step fields in the example I have on my word document there shows 16 boxes looking like this
1 2 3 4
5 6 7 9
9 10 11 12
13 14 15 16
When I input 3 for start 15 for stop and 4 for step the boxes that are to be yellow are 3, 7, 11, 15...however they are all turning blue and was wondering if anyone could take a look at my loop and let me know if I am doing something wrong in it or something else.
java Syntax (Toggle Plain Text)
//packages to import import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Checkerboard extends Frame implements ActionListener { private Panel topPanel; private TextArea topDisplay[]; private Panel bottomPanel; private TextField startField = new TextField(10); private TextField stopField = new TextField(10); private TextField stepField = new TextField(10); private Label startLabel = new Label ("Start"); private Label stopLabel = new Label ("Stop"); private Label stepLabel = new Label ("Step"); private Button goButton; private Button clearButton; private boolean clearText; private boolean first; private int start; private int stop; private int step; //constructor methods public Checkerboard() { //construct components and initialize beginning values topPanel = new Panel(); topDisplay = new TextArea[16]; goButton = new Button("Go"); clearButton = new Button("Clear"); first = true; bottomPanel = new Panel(); int start = 0; int stop = 0; int step = 0; bottomPanel.add(startField); bottomPanel.add(stopField); bottomPanel.add(stepField); bottomPanel.add(startLabel); bottomPanel.add(stopLabel); bottomPanel.add(stepLabel); bottomPanel.add(goButton); goButton.addActionListener(this); bottomPanel.add(clearButton); clearButton.addActionListener(this); clearText = true; //set layouts for the Frame and Panels setLayout(new BorderLayout()); topPanel.setLayout(new GridLayout(4, 4, 10, 10)); bottomPanel.setLayout(new GridLayout(3, 3, 5, 5)); //construct the Display for(int i = 0; i <= 15; i++) { topDisplay[i] = new TextArea(null, 3, 5, 3); topDisplay[i].setText(String.valueOf(i+1)); topDisplay[i].setEditable(false); topPanel.add(topDisplay[i]); //topPanel.setEditable("false"); } //add components to frame add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.CENTER); //allow the x to close the application addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } //end window adapter ); } public static void main(String args[]) { Checkerboard f = new Checkerboard(); f.setTitle("Checkerboard Array"); f.setBounds(50, 100, 300, 400); f.setLocationRelativeTo(null); f.setVisible(true); } //end main public void actionPerformed(ActionEvent e) { //convert data in TextField to int int start = Integer.parseInt(startField.getText()); int stop = Integer.parseInt(stopField.getText()); int step = Integer.parseInt(stepField.getText()); //test go String arg = e.getActionCommand(); //go button was clicked if(arg.equals("Go")) { for(int i = 0; i <=16; i++) topDisplay[i].setBackground(Color.blue); for(int i = start; i <= stop; step++) topDisplay[i].setBackground(Color.yellow); } //end the if go //clear button was clicked if(arg.equals("Clear")) { clearText = true; startField.setText(""); stopField.setText(""); stepField.setText(""); first = true; setBackground(Color.white); startField.requestFocus(); } //end the if clear }//end action listener }//end class
![]() |
Similar Threads
- My URLs are blinded by their cloaks! (Geeks' Lounge)
Other Threads in the Java Forum
- Previous Thread: First, best, worst fit java program - need help debugging
- Next Thread: Curved vertex for swing containers.
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working






