import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String args[]) {
new Test().go();
}
public void go()
{
Ball ball = new Ball();
Pole pole = new Pole();
frame.getContentPane().add( pole);
frame.setSize(600 , 600);
frame.setVisible(true);
}
class Ball extends JPanel
{
public void paintComponent(Graphics g)
{
//由下面可知,坐标原点是左上角或者是以坐标为原点,从左上角开始画起
g.fillOval(100 , 100 , 30 , 30);
g.setColor(Color.white);
g.fillOval(100 , 100 , 20 , 20);
}
}
class Pole extends JPanel
{
public void paintComponent(Graphics g)
g.setColor(Color.white);
g.fillRect(300 , 300 , 2 , 10);
}
}
}
import javax.swing.*;
public class Test {
public static void main(String args[]) {
new Test().go();
}
public void go()
{
Ball ball = new Ball();
Pole pole = new Pole();
JFrame frame = new JFrame();
//下面两行,有一行必须注释,因为无法两个图形都显示出来
//frame.getContentPane().add( ball);
frame.getContentPane().add( pole);
frame.getContentPane().add( pole);
frame.setSize(600 , 600);
frame.setVisible(true);
}
class Ball extends JPanel
{
public void paintComponent(Graphics g)
{
//由下面可知,坐标原点是左上角或者是以坐标为原点,从左上角开始画起
g.fillOval(100 , 100 , 30 , 30);
g.setColor(Color.white);
g.fillOval(100 , 100 , 20 , 20);
}
}
class Pole extends JPanel
{
public void paintComponent(Graphics g)
{
//由下面可知,坐标原点在左边或者是以坐标为原点,从左边开始画起
g.fillRect(300 , 300 , 40 , 10);g.setColor(Color.white);
g.fillRect(300 , 300 , 2 , 10);
}
}
}