![]() |
IOBit Software
|
|
|
||||||
| Programming Place to discuss programming including HTML, Java, C++, MySQL and others. |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Ok this is a very basic problem but I can't figure out what's wrong.
I'm learning the awt (Abstract Windowing Toolkit) package (I know it's old but that's what the Java book has) Anyway, I wrote a small program just to see how it all fits together, it's supposed to give me a window titled "Animals" with 3 colored buttons. Here's the code: import java.awt.*; public class TestAwt { public static void main(String[] args) { Frame frame=new Frame("Animals"); Panel panel=new Panel(); Button b1=new Button("Dog"); Button b2=new Button("Cat"); Button b3=new Button("Hamster"); b1.setForeground(Color.white); b1.setBackground(Color.blue); b2.setForeground(Color.white); b2.setBackground(Color.blue); b3.setForeground(Color.white); b3.setBackground(Color.blue); panel.setBackground(Color.blue); panel.add(b1); panel.add(b2); panel.add(b3); frame.add(panel); frame.setVisible(true); frame.setSize(200,200); } } For some reason all it gives me is the frame (overall window) but no components inside (no buttons, no background [panel]), which is very strange, considering that this program (a simpler version of the previous one) works: import java.awt.*; public class Wtf { public static void main(String[] args) { Frame frame=new Frame("Alice in wonder land"); Panel panel=new Panel(); Button b=new Button("Press"); panel.add(b); frame.add(panel); frame.setSize(300,300); frame.setVisible(true); panel.setBackground(Color.black); } } What am I missing here? |
| Sponsored links |
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unknown Java error, possible virus/hacker? | kwyjibo | Software | 1 | 11-15-03 18:07 |
| Help with Java please. | ColonelAngus | Programming | 7 | 07-15-03 07:43 |
| IE and java | morlok | Software | 17 | 07-13-03 15:39 |