比方说我要画一个圆,但是我要确定这个圆的颜色,而不是画布的背景颜色,这该如何确定呢? 
也请仙人顺便帮小子看看这个吧http://topic.csdn.net/u/20100802/14/91a73580-a191-4bc4-8a47-0197e174ba19.html

解决方案 »

  1.   


    import javax.swing.*;
    import java.awt.*;
    public class drawOval  {
    public static void main(String [] args){
    EventQueue.invokeLater(new Runnable(){
    public void run(){
    JFrame frame = new JFrame();
    frame.setSize(300, 200);
    MyPanel pan = new MyPanel();
    frame.add(pan);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    });
    }
    }
    class MyPanel extends JPanel{
    public void paintComponent(Graphics g){
    g.setColor(Color.RED);
    g.fillOval(100, 100, 20, 20);
    }
    }还是多看看书吧 不好说啊
      

  2.   

      类EventQueue的使用貌似没必要!!! 
      

  3.   

    这个很详细了··学过AWT了没?
      

  4.   


    package com;
    import javax.swing.*;import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.*;
    public class test3 {
    public static void main(String args[]){
    Circle3 c1=new Circle3();
    }}
    class Circle3 extends JFrame{
    int x,y;
    public Circle3(){
    init();this.setBounds(50,50,700,700);
    this.setVisible(true);
    }
    public void paint(Graphics g){
    g.setColor(Color.red);
    g.fillOval(x,y,30,30);}
    void init(){
    this.addMouseListener(new MouseAdapter(){
    public void mouseClicked(MouseEvent e){
    x=e.getPoint().x;
    y=e.getPoint().y;
    repaint();
    }
    });
    }
    }
      

  5.   

    怎么没有必要?Core Java(Java 核心技术)上明确指出最好用EventQueue初始化Swing程序
      

  6.   


    g.setColor(Color.red);g.setBackgroundColor(Color.blue);