请教各位大哥
我在做一个毕业论文的时候,我已经新建了一个表格(jtable),可是我不知道怎么去得到用户输入的数据
请各位帮帮忙,帮我指点指点,我在此多谢了啊

解决方案 »

  1.   

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    public class Lb extends JFrame implements ActionListener{
    JButton b1 = new JButton("open");
    JButton b2 = new JButton("save");
    JPanel p = new JPanel();
    JTextArea jta = new JTextArea();
    JScrollPane jsp = new JScrollPane(jta);

    JFileChooser jfc = new JFileChooser();

        public Lb() {
         this.add(jsp);
         this.add(p,BorderLayout.NORTH);
         p.add(b1);
         p.add(b2);
        
         b1.addActionListener(this);
         b2.addActionListener(this);
        
         this.setSize(320,240);
         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
         this.setVisible(true);
        }
        
        public void actionPerformed(ActionEvent e){
         String s = e.getActionCommand();
         if(s.equals("save")){
         save();
         }else if(s.equals("open")){
         open();
         }
        }
        
        public void open(){
         int n = jfc.showOpenDialog(this);
         String s,text="";
        
         if(n==0){
         File f = jfc.getSelectedFile();

         try{
         FileReader fr = new FileReader(f);
         BufferedReader br = new BufferedReader(fr);
        
         while((s=br.readLine())!=null){
         text+=s+"\n";
         }
        
         jta.setText(text);
        
         br.close();
         fr.close();
         }catch(FileNotFoundException e){
         e.printStackTrace();
         }catch(IOException e){
         e.printStackTrace();
         }
         }else {
         JOptionPane.showMessageDialog(this,"choose a file please.","系统提示",JOptionPane.INFORMATION_MESSAGE);
         }
        }
        
        public void save(){
         if(jfc.showSaveDialog(this)==JFileChooser.APPROVE_OPTION){
         File f = jfc.getSelectedFile();

         try{
         FileWriter fr = new FileWriter(f);
        
         fr.write(jta.getText().replaceAll("\n","\r\n"));
        
         fr.close();
         }catch(FileNotFoundException e){
         e.printStackTrace();
         }catch(IOException e){
         e.printStackTrace();
         }
         }else{
         JOptionPane.showMessageDialog(this,"choose a file please.");
         }
        }
            
        public static void main(String[] args) {
            new Lb();
        }
    }
    希望对你有帮助!~~