目前程序如下,请问,如何在Ex14中实现DrawPanel中的画图功能?
package Ex14;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.color.*;
public class DrawPanel extends JPanel
{
private MyColorChooser mcc;
public Color mycolor;
public DrawPanel()
{
mcc = new MyColorChooser();
}
public void set()
{
mycolor = mcc.mycolorchooser;
repaint();
}
public void paintComponent( Graphics g )
{
super.paint( g );
g.setColor( mycolor );
g.fillRect( 200, 100, 200, 100 );
}
}
package Ex14;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Ex14 extends JApplet
{
private MyColorChooser mcc;
private DrawPanel dp;
private JButton button;
private FlowLayout layout;
public Ex14()
{
Container container = getContentPane();
layout = new FlowLayout();
container.setLayout( layout );
mcc = new MyColorChooser();
dp = new DrawPanel();
container.add( mcc );
dp.repaint();
button = new JButton("OK");
button.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent actionEvent )
{
dp.repaint();
}
}
);
container.add( button );
setSize( 800, 600 );
setVisible( true );
}
}