📄 deserialsample.java
字号:
//DeSerialSample.Java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import com.borland.jbcl.layout.*;
import java.io.*;
public classDeSerialSample extends JFrame
{
private JPanel contentPane;
private XYLayout xyLayout1 = new XYLayout();
private JButton jButton1 = new JButton();
private DrawPicture area=new DrawPicture();
ArrayList picture=new ArrayList();
public DeSerialSample() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jButton1.setRolloverEnabled(true);
jButton1.setText("Reatore");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(xyLayout1);
this.setSize(new Dimension(400, 200));
this.setTitle("Serial Sample");
area.addMouseListener(draw);
contentPane.add(jButton1, new XYConstraints(109, 3, -1, -1));
contentPane.add(area, new XYConstraints(39, 54, 310, 227));
}
void jButton1_actionPerformed(ActionEvent e) {
try{
ObjectInputStream in=new ObjectInputStream(new FileInputStream("objFile"));
picture=(ArrayList)(in.readObject());
in.close();
repaint();
}
catch(Exception ex){
}
}
public static void main(String[] args){
SerialSample frame1=new SerialSample();
frame1.setSize(400,400);
frame1.setVisible(true);
}
MouseAdapter draw=new MouseAdapter(){
public void mousePressed(MouseEvent e){
Point p=new Point(e.getX(),e.getY());
picture.add(p);
repaint();
}
};
class DrawPicture extends JTextArea{
DrawPicture(){
super("",15,20);
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
int i=0;
while(i<picture.size()){
Point p0=(Point)(picture.get(i++));
int x=p0.x;
int y=p0.y;
g.drawOval(x,y,50,50);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -