F.eks. noget ala:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingTest extends JFrame implements ActionListener
{
private JButton button;
public SwingTest()
{
//swing init
setTitle("TestKlasseSwing");
JFrame.setDefaultLookAndFeelDecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new GridLayout(5, 2));
//components
button = new JButton("Tryk mig!");
button.addActionListener(this);
getContentPane().add(button);
//Center Frame
setSize(320, 200);
setLocationRelativeTo(this);
}
public void actionPerformed(ActionEvent e)
{
new MyDialog("hello world").show();
}
public static void main(String args[])
{
new SwingTest().show();
}
}
class MyDialog extends JDialog
{
public MyDialog(String text)
{
setTitle("MyDialog");
getContentPane().add(new JLabel(text));
setSize(100, 100);
setLocationRelativeTo(this);
}
}
Hvis du manger lidt tutorials ang. swing så kig her:
http://java.sun.com/docs/books/tutorial/uiswing/