null
. We pass the delegate a copy of the Graphics
object to protect.....
似乎也没写清楚用法,反正是没看明白...
null
. We pass the delegate a copy of the Graphics
object to protect.....
似乎也没写清楚用法,反正是没看明白...
//一段小程序 供参考。。。 import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class ShowColors2 extends JFrame {
private JButton changeColorButton; private Color color = Color.LIGHT_GRAY; private Container container;
public ShowColors2(){ super(" Using JColorChooser "); container = getContentPane(); container.setLayout( new FlowLayout()); changeColorButton = new JButton ("Change Color "); changeColorButton.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent event ){ color = JColorChooser.showDialog(ShowColors2.this, "Choose a color ", color);
if (color == null) color = Color.LIGHT_GRAY; container.setBackground(color);
} }) ; container.add( changeColorButton ); setSize(400,130); setVisible(true);
}
public static void main (String args[] ){ ShowColors2 application = new ShowColors2(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); } }
import java.awt.*; import javax.swing.*;
public class LinesRectsOvals extends JFrame { public LinesRectsOvals(){ super("Drawing lines , rectangles ans ovals "); setSize(400,165); setVisible(true);
} public void paint (Graphics g){ super.paint(g); g.setColor(Color.RED); g.drawLine(5,30,350,30); g.setColor(Color.BLUE); g.drawRect(5,40,90,55); g.fillRect(100,40,90,50);
g.setColor(Color.CYAN); g.fillRoundRect(195,40,90,55,50,50); g.drawRoundRect(290,40,90,55,20,20);
g.setColor(Color.YELLOW); g.draw3DRect(5,100,90,55,true); g.fill3DRect(100,100,90,55,false); g.setColor( Color.MAGENTA); g.drawOval( 195,100,90,55); g.fillOval(290,100,90,55); }
public static void main(String args[]){ LinesRectsOvals application = new LinesRectsOvals(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
} }