import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class XORPanel extends JPanel {
XORPanel() {
setBackground(Color.black);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.fillRect(10, 10, 80, 30);
g.setColor(Color.green);
g.fillRect(50, 20, 80, 30);
g.setColor(Color.blue);
g.fillRect(130, 40, 80, 30);
g.setXORMode(Color.green);
g.fillRect(90, 30, 80, 30);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("XOR");
frame.setSize(300, 200);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new XORPanel());
frame.show();
}
}
|