We are using Turbo JBuilder from Borland, it uses the Eclipse IDE.
The following code doesn't show the label or buttons until you try and resize the window. Does anyone have any idea why?
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleApp extends JFrame implements ActionListener
{
JLabel lbl = new JLabel("Hello World");
JButton btn1 = new JButton("Red");
JButton btn2 = new JButton("Green");
Container content = this.getContentPane();
public SimpleApp()
{
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
content.add(lbl);
content.add(btn1);
btn1.addActionListener(this);
content.add(btn2);
btn2.addActionListener(this);
this.setVisible(true);
this.setSize(300,200);
}
public static void main(String[] args)
{
new SimpleApp();
}
public void actionPerformed(ActionEvent e)
{
JButton b = (JButton) e.getSource();
if(b == btn1)
lbl.setForeground(Color.RED);
else
lbl.setForeground(Color.GREEN);
}
}


Sign In
Create Account

Back to top









