基本使用
public class drawCircle extends JFrame {
@SuppressWarnings("all")
private MyPanel myPanel = null;
public static void main(String[] args) {
new drawCircle().drawCircle();
}
public void drawCircle(){
myPanel = new MyPanel();
this.add(myPanel);
this.setSize(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class MyPanel extends JPanel{
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawOval(10,10,100,100);
g.drawLine(10,10,100,100);
g.drawRect(10,10,100,100);
g.setColor(Color.green);
g.fillRect(10,10,100,100);
g.fillOval(10,10,100,100);
Image image = Toolkit.getDefaultToolkit().getImage(MyPanel.class.getResource("/2.jpeg"));
g.drawImage(image,10,10,690,670,this);
g.setFont(new Font("隶书",Font.BOLD,30));
g.drawString("刘亦菲",40,40);
}
}