public class Gui extends JFrame{
private JPanel p1,p2;
private JButton b1;
public Gui(){
p1 = new JPanel();
p2 = new JPanel();
b1 = new JButton("画");
p1.add(b1);
this.add(p1,BorderLayout.NORTH);
this.add(p2, BorderLayout.CENTER);
this.setVisible(true);
this.setBounds(100,100,450,580);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Painter painter = new Painter();
b1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
painter.setShape(new Circle(100,100,100));
painter.draw(p2.getGraphics());
}
});
}
public static void main(String[] args) {
new Gui();
}
}
public class Painter {
private Shape shape;
public void setShape(Shape shape) {
this.shape = shape;
}
public void draw(Graphics g){
shape.draw(g);
}
}
public abstract interface Shape {
public abstract void draw(Graphics g);
}
public class Circle implements Shape {
public int r;
public int x;
public int y;
public Circle(int r, int x, int y) {
super();
this.r = r;
this.x = x;
this.y = y;
}
public void draw(Graphics g) {
g.drawOval(x, y, r, r);
}
}
public class Gui extends JFrame{ private JPanel p1,p2; private JButton b1; public Gui(){ p1 = new JPanel(); p2 = new JPanel(); b1 = new JButton("画"); p1.add(b1); this.add(p1,BorderL...