Skip to content

Instantly share code, notes, and snippets.

@twmht

twmht/Main.java Secret

Created May 18, 2014 09:04
public class Main {
public static void main(String[] args) {
new MyFrame();
}
}
import java.io.IOException;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
public class MyFrame extends JFrame implements ActionListener {
public MyFrame() {
super("MyFrame");
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JLabel("Thread-Per-Message Sample"));
JButton button = new JButton("Execute");
getContentPane().add(button);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Service.service();
}
}
public class Service {
public static void service() {
System.out.print("service");
for (int i = 0; i < 50; i++) {
System.out.print(".");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
System.out.println("done.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment