framework.java

來源:互聯網
上載者:User

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.io.*;

import javax.swing.JOptionPane;
public class framework extends JFrame {

 private static final long serialVersionUID = 1L;

 private JPanel jContentPane = null;

 private JButton jButton1 = null;

 private JButton jButton2 = null;

 private JTextArea jTextArea = null;

 private JTextField jTextField = null;

 /**
  * This method initializes jButton1
  *
  * @return javax.swing.JButton
  */
 private JButton getJButton1() {
  if (jButton1 == null) {
   jButton1 = new JButton();
   jButton1.setBounds(new Rectangle(556, 23, 60, 28));
   jButton1.setText("讀出");
   jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent e) {

     String name =jTextField.getText();
     
     File ss = new File(name);
     try {
      FileReader a = new FileReader(ss);
      BufferedReader br = new BufferedReader(a);

      String s = br.readLine();
      while (s != null)// 值非空
      {
       jTextArea.setText(s);
       s = br.readLine();

      }
      br.close();

     }

    
     catch (IOException e1) {

      JOptionPane.showMessageDialog(null, "檔案路徑錯誤,請重新輸入");

     }
    }
   });

  }
  return jButton1;
 }

 /**
  * This method initializes jButton2
  *
  * @return javax.swing.JButton
  */
 private JButton getJButton2() {
  if (jButton2 == null) {
   jButton2 = new JButton();
   jButton2.setBounds(new Rectangle(559, 249, 60, 28));
   jButton2.setText("儲存");
   jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent e) {
     String name =jTextField.getText();
     String s=null;
     File save = new File(name);
     try {
      s=jTextArea.getText();
      
      //String ss==s.readLine();
      //BufferedReader sr=new BufferedReader(s);
      PrintWriter out = new PrintWriter(new FileWriter(save));
      if (!s.equals("")) {
       out.println(s);
      }
      out.close();
     
     } catch (IOException e2) {
      
      JOptionPane.showMessageDialog(null, "檔案路徑錯誤,請重新輸入");
     }
     
     
     
     
     
    }
     
     
     
     
     
     
    
   });
  }
  return jButton2;
 }

 /**
  * This method initializes jTextArea
  *
  * @return javax.swing.JTextArea
  */
 private JTextArea getJTextArea() {
  if (jTextArea == null) {
   jTextArea = new JTextArea();
   jTextArea.setBounds(new Rectangle(2, 68, 459, 224));
   jTextArea.setText("");
  }
  return jTextArea;
 }

 /**
  * This method initializes jTextField
  *
  * @return javax.swing.JTextField
  */
 private JTextField getJTextField() {
  if (jTextField == null) {
   jTextField = new JTextField();
   jTextField.setBounds(new Rectangle(22, 13, 211, 44));
   jTextField.setText("");

  }
  return jTextField;
 }

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    shurushuchu thisClass = new shurushuchu();
    thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    thisClass.setVisible(true);
   }
  });
 }

 /**
  * This is the default constructor
  */
 public framework() {
  super();
  initialize();
 }

 /**
  * This method initializes this
  *
  * @return void
  */
 private void initialize() {
  this.setSize(641, 339);
  this.setContentPane(getJContentPane());
  this.setTitle("JFrame");
 }

 /**
  * This method initializes jContentPane
  *
  * @return javax.swing.JPanel
  */
 private JPanel getJContentPane() {
  if (jContentPane == null) {
   jContentPane = new JPanel();
   jContentPane.setLayout(null);
   jContentPane.add(getJButton1(), null);
   jContentPane.add(getJButton2(), null);
   jContentPane.add(getJTextArea(), null);
   jContentPane.add(getJTextField(), null);
  }
  return jContentPane;
 }

} // @jve:decl-index=0:visual-constraint="10,10"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.