⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 open.java

📁 java语言实现的一个画图小程序,可以实现绘图
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package drawfigure;import java.awt.Color;import java.io.IOException;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.*;import java.awt.event.*;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;public class Open extends JFrame{   int i,sx,sy,x,y,blue,green,red;    String bool;    boolean fill;    JLabel  fname;    JLabel  path;    JTextField jTextFieldfname;    JTextField jTextFieldpath;    JButton open;    JButton exit;     Open(final DrawFigure draw)     {          this.setLayout(null);//设置布局管理器为null        File file=new File("画图文件");        if(!file.exists()) file.mkdir();     	//初始化各个控件    	fname=new JLabel("文件名");    	path=new JLabel("保存路径");    	jTextFieldfname=new JTextField();            jTextFieldpath=new JTextField(file.getAbsolutePath());      	open= new JButton("打开");    	exit=new JButton("取消");    	//设置控件位置    	this.fname.setBounds(10,10,80,20);        this.path.setBounds(10,50,80,20);        this.jTextFieldfname.setBounds(100,10,200,20);    	this.jTextFieldpath.setBounds(100,50,200,20);        this.open.setBounds(30, 100, 100, 30);        this.exit.setBounds(200, 100, 100, 30);    	//将控件添加到面板上        this.add(fname);        this.add(path);        this.add(jTextFieldfname);        this.add(jTextFieldpath);        this.add(open);        this.add(exit);    	this.setBounds(330,300,350,200);    	this.setTitle("打开");    	this.setVisible(true);     open.addActionListener(new ActionListener()     {public void actionPerformed(ActionEvent e)      {  draw.stack.clear();         draw.delStack.clear();         String p,f;         p=jTextFieldpath.getText();         f=jTextFieldfname.getText();         File pa=new File(p,f);             try {                    if (!pa.exists()) {                       JOptionPane.showMessageDialog(null,"文件不存在","错误",JOptionPane.INFORMATION_MESSAGE);                     }                   else{                       BufferedReader output = new BufferedReader(new FileReader(pa));                     String str;                    while((str=output.readLine())!=null){                      int h=0,t=1;                      while(str.charAt(t)!='\t')                              {t++;}                      i=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                      while(str.charAt(t)!='\t')                           {t++;}                      sx=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                      while(str.charAt(t)!='\t')                           {t++;}                      sy=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                      while(str.charAt(t)!='\t')                           {t++;}                      x=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                        while(str.charAt(t)!='\t')                           {t++;}                      y=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                      while(str.charAt(t)!='\t')                             {t++;}                      blue=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                        while(str.charAt(t)!='\t')                           {t++;}                      green=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                        while(str.charAt(t)!='\t')                           {t++;}                      red=Integer.parseInt(str.substring(h,t));h=t+1;t=t+2;                        while(str.charAt(t)!='\t')                           {t++;}                      bool=str.substring(h,t);                      if(bool.equals("true")) fill=true;                      else fill=false;                      Color c = new Color(red,green,blue);                      if(i==1)                      {                      Lines lines = new Lines();                      lines.setValue(sx, sy, x, y, c);                      draw.stack.push(lines);                      }                       if(i==2)                     {                         Circle circle = new Circle();                        circle.setValue(sx, sy, x, y, c,fill);                        draw.stack.push(circle);                      }                      if(i==3)                      {                       Rectangle rectangle = new Rectangle();                        rectangle.setValue(sx, sy, x, y, c, fill);                        draw.stack.push(rectangle);                       }               }                                         output.close();setVisible(false);                     draw.repaint();                      }                    } catch (IOException ex) {                        Logger.getLogger(Save.class.getName()).log(Level.SEVERE, null, ex);                      }                                          }    });     exit.addActionListener(new ActionListener()     {public void actionPerformed(ActionEvent e)      {          setVisible(false);repaint();      }    });      }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -