/*
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import javax.swing.*;
class clock extends Thread{
JLabel clockL= new JLabel();
public void run() {
String clockText;
int hour,min,second;
while(true) {
Calendar c= Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
min = c.get(Calendar.MINUTE);
second = c.get(Calendar.SECOND);
clockText = Integer.toString(hour-12);
clockText = clockText.concat("시 ");
clockText = clockText.concat(Integer.toString(min));
clockText = clockText.concat("분 ");
clockText = clockText.concat(Integer.toString(second));
clockText = clockText.concat("초 ");
clockL.setText(clockText);
try {
Thread.sleep(1000);
}
catch(InterruptedException e) {
return;
}
}
}
}
public class Main extends JFrame{
public Main(){
setTitle("Digital clock");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
clock cl = new clock();
c.add(cl.clockL);
setSize(300,300);
setVisible(true);
cl.start();
}
public static void main(String[] args) {
new Main();
}
}
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame{
MyPanel panel = new MyPanel();
public Main(){
setTitle("Random Circle");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(500,500);
setVisible(true);
}
class MyPanel extends JPanel implements Runnable{
int x=0,y=0;
public MyPanel() {
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
run();
}
});
}
public void run() {
while(true) {
x=(int)(Math.random()*300);
y=(int)(Math.random()*300);
try {
Thread.sleep(400);
}catch(InterruptedException e) {
return;
}
repaint();
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawOval(x, y, 50, 50);
}
}
public static void main(String[] args) {
new Main();
}
}