/*
* ScreenSavers.java
*
* Created on 2007年11月3日, 下午8:21
*/
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.LayoutStyle;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
* @author xuqidong
*/
public class ScreenSavers extends javax.swing.JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
// 变量声明 - 不进行修改
private JComboBox comboBox;
private javax.swing.JToggleButton ellipseButton;//按钮圆
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton saveButton;//保存按钮
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton colorChooserButton;//颜色选择按钮
private javax.swing.JButton clearButton;//清除按扭
private javax.swing.JButton backButton;//返回按钮
private ImageBoard imageBoard;
private JCheckBox checkBox = new JCheckBox("填充颜色");
// 变量声明结束
BufferedImage image;
/** Creates new form ScreenSavers */
public ScreenSavers() {
super("画板");
setBounds(new Rectangle(100, 50, 578, 350));
initComponents();
imageBoard.setType("");
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setAlwaysOnTop(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
checkBox.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
imageBoard.setFull(checkBox.isSelected());
}
});
comboBox = new JComboBox();
comboBox.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent arg0) {
imageBoard.setBasicStroke(Integer.parseInt(arg0.getItem().toString()));
}
});
comboBox.setModel(new DefaultComboBoxModel(new String[] {"1", "3", "5", "7", "9", "11"}));
JLabel label;
label = new JLabel();
label.setText("设置线条粗细");
final GroupLayout groupLayout = new GroupLayout((JComponent) getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING, groupLayout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(ellipseButton, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addComponent(jButton2, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addComponent(jButton3, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addComponent(jButton4, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addComponent(colorChooserButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(checkBox, GroupLayout.PREFERRED_SIZE, 86, Short.MAX_VALUE)))
.addGroup(GroupLayout.Alignment.TRAILING, groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(comboBox, 0, 86, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(label, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(imageBoard, GroupLayout.PREFERRED_SIZE, 354, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(clearButton, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
.addComponent(saveButton, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
.addComponent(jButton11, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
.addComponent(jButton10, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
.addComponent(backButton, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
.addContainerGap())
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(17, 17, 17)
.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(jButton10)
.addGap(17, 17, 17)
.addComponent(jButton11)
.addGap(25, 25, 25)
.addComponent(saveButton)
.addGap(60, 60, 60)
.addComponent(backButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(clearButton))
.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(ellipseButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
.addGap(6, 6, 6)
.addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
.addGap(6, 6, 6)
.addComponent(jButton4)
.addGap(14, 14, 14)
.addComponent(colorChooserButton)
.addGap(10, 10, 10)
.addComponent(checkBox)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(label, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(imageBoard, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 276, GroupLayout.PREFERRED_SIZE)))
.addGap(81, 81, 81))
);
getContentPane().setLayout(groupLayout);
pack();
}
private void initComponents() {
imageBoard = new ImageBoard();
ellipseButton = new javax.swing.JToggleButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
saveButton = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
colorChooserButton = new javax.swing.JButton();
clearButton = new javax.swing.JButton();
backButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
imageBoard.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
BorderLayout jPanel1Layout = new BorderLayout();
imageBoard.setLayout(jPanel1Layout);
ellipseButton.setText("\u5706");
ellipseButton.addActionListener(new java.awt.event
- 1
- 2
前往页