public class Test {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
JFrame kkk = new lll();
}
}
class lll extends JFrame{
public lll(){
this.setTitle("test");
this.setSize(500,400);
this.setVisible(true);
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.drawLine(10, 10, 100, 100);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFrame extends JFrame implements ActionListener{
private MyPanel panel;
public MyFrame(){
this.setSize(500, 500);
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLayout(new BorderLayout());
panel =new MyPanel();
this.add(panel,BorderLayout.CENTER);
JButton rotate=new JButton("rotate");
rotate.addActionListener(this);
this.add(rotate,BorderLayout.SOUTH);
}
@Override
public void actionPerformed(ActionEvent e) {
panel.angle+=45;
panel.drawRotateLine();
}
public static void main(String[] args){
new MyFrame();
}
}
class MyPanel extends JPanel{
int angle = 0;
public void drawRotateLine(){
Graphics2D g2d = (Graphics2D) this.getGraphics();
g2d.clearRect(0, 0, 500, 500);
g2d.rotate(angle,250,250);
g2d.drawLine(250, 250, 100, 0);
}
}