/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
double b1=0, b2=0, b3=0, b4=0;
public Main() {
setTitle("마우스 드레깅으로 타원 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel p1 = new JPanel();
MyPanel p2 = new MyPanel();
p1.setBackground(Color.gray);
add(p1, BorderLayout.NORTH);
add(p2, BorderLayout.CENTER);
JLabel ab = new JLabel("apple");
JTextField a = new JTextField(5);
JLabel cd = new JLabel("cherry");
JTextField c = new JTextField (5);
JLabel st = new JLabel("strawberry");
JTextField s = new JTextField (5);
JLabel pq = new JLabel("prune");
JTextField p = new JTextField (5);
JLabel a1 = new JLabel("apple %");
a1.setForeground(Color.red);
p2.add(a1);
JLabel a2 = new JLabel("cherry %");
a2.setForeground(Color.BLUE);
p2.add(a2);
JLabel a3 = new JLabel("strawberry %");
a3.setForeground(Color.PINK);
JLabel a4 = new JLabel("prune %");
a4.setForeground(Color.ORANGE );
p2.add(a4);
p.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int s1 = Integer.valueOf(a.getText());
int s2 = Integer.valueOf(c.getText());
int s3 = Integer.valueOf(s.getText());
int s4 = Integer.valueOf(p.getText());
int sum = s1+s2+s3+s4;
b1 = (double)s1/sum*100;
b2 = (double)s2/sum*100;
b3 = (double)s3/sum*100;
b4 = (double)s4/sum*100;
a1.setText("apple "+ (int)b1 +" %");
a2.setText("cherry "+ (int)b2 +" %");
a3.setText("strawberry "+ (int)b3 +" %");
a4.setText("prune "+ (int)b4 +" %");
p2.repaint();
p2.revalidate();
}
});
p1.setLayout(new FlowLayout());
p1.add(ab);
p1.add(a);
p1.add(cd);
p1.add(c);
p1.add(st);
p1.add(s);
p1.add(pq);
p1.add(p);
setSize(1000, 1000);
setVisible(true);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.fillArc(250,250,500,500,0,(int)(b1*3.6));
g.setColor(Color.blue);
g.fillArc(250,250,500,500,(int)(b1*3.6),(int)(b2*3.6));
g.setColor(Color.PINK);
g.fillArc(250,250,500,500,(int)(b1*3.6)+(int)(b2*3.6),(int)(b3*3.6));
g.setColor(Color.ORANGE);
int num=360-((int)(b1*3.6)+(int)(b2*3.6)+(int)(b3*3.6));
g.fillArc(250,250,500,500,(int)(b1*3.6)+(int)(b2*3.6)+(int)(b3*3.6),num);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.*;
public class Main extends JFrame {
public Main() {
setTitle("");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(new MyPanel());
setSize(500,500);
setVisible(true);
}
class MyPanel extends JPanel {
private ImageIcon icon = new ImageIcon(".png");
private Image img = icon.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 20, 20, this);
}
}
public static void main(String[] args) {
new Main();
}
}