Just a start-up example , let you get a rough idea how to init a desktop application:
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class TestJFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button = new JButton();
button.setText("im Paul");
button.setSize(50, 50);
button.addActionListener(new LoveListener(panel));
panel.add("Center", button);
frame.add(panel);
// frame.show();
//frame.setBounds(10, 10, 10, 10);
//frame.pack();
frame.setSize(100, 100);
JFrame.setDefaultLookAndFeelDecorated(true);
Image icon = Toolkit.getDefaultToolkit().getImage("icon.png");
frame.setIconImage(icon);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
static class LoveListener implements ActionListener{
private JPanel panel;
public LoveListener(JPanel panel){this.panel=panel;}
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(panel, "Love Haohao!");
System.out.println("Love Haohao!");
}
}
}
to be continued