import java.awt.*;
import javax.swing.*;
public class KeHouTuoYuan extends JFrame{
public KeHouTuoYuan(){
setSize(500,500);
setTitle("课后的题");
setLocation(200,200);
setVisible(true);
}
public static void main(String[] args) {
KeHouTuoYuan k = new KeHouTuoYuan();
DrawPanel d = new DrawPanel();
k.setContentPane(d);
}
}
class DrawPanel extends JPanel{
public DrawPanel(){
setBackground(Color.GREEN);
setSize(400,400);
setLocation(50,50);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.translate(200,200);
g.drawOval(-100,-100,200,200);
g.setColor(Color.GRAY);
g.fillOval(-100,-100,200,50);
g.setColor(Color.BLUE);
g.drawLine(0, 0, 0, 50);
g.drawLine(0, 0,50, 0);
g.setColor(Color.BLACK);
g.drawRect(-100,-100,100,100);
g.setColor(Color.WHITE);
g.drawRect(0,0,100,100);
g.setColor(Color.RED);
g.drawLine(-100, -100, 100, 100);
}
}
Tags -
java ,
gui课后习题
文章来源:
http://www.tt-shopping.com/kevinlau/read.php/120.htm