Need a runnable Java Application
I'm in need of a small, short and sweet Java application that will show a window form with a button and when I click on the button it will paint a message on the window. I think it should be something like class MyForm extends Frame implements Runnable but I'm not sure but it needs to run in a Thread.
Does anyone know if there is something similar to this around here or can someone just give me a simple example.
Thanks in advance.
Re: Need a runnable Java Application
I hope this helps:
Code:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MyFrame extends JFrame {
private JButton btnPaint;
public MyFrame() {
btnPaint = new JButton("Paint");
btnPaint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread th = new Thread(new Runnable() {
public void run() {
getGraphics().drawString("My String", 50, 100);
}
});
th.start();
}
});
this.add(btnPaint, BorderLayout.NORTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(200, 200);
this.setVisible(true);
}
public static void main(String[] args) {
new MyFrame();
}
}