Mình mới làm quen với Java Swing được vài tuần nay , mình đang thử làm 1 giao diện cho người dùng đưa vào 1 file văn bản (txt), sau đó cho hiện ra các nội dung trong file ấy theo thứ tự tăng dần và giảm dần ( mình chỉ mới làm được đến load dữ liệu vào và chưa sắp xếp thứ tự được), và đưa ra tên và số điểm của người cao điểm nhất và người thấp điểm nhất, đây là code của mình, mọi người giúp mình nha
Mã:
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.filechooser.*;

/**
*
*/

/**
* @author Michael Thai
*
*/
public class DemoReadFile extends JFrame {
    private JTextField txtinput = new JTextField();
    private JTextArea txtoutput = new JTextArea();
    private JScrollPane scroll = new JScrollPane(txtoutput);
    private JButton btnbrowse = new JButton("Browse"), btnload = new JButton(
            "Load"), btnclear = new JButton("Clear"),
            btnclearall = new JButton("Clear All");

    public DemoReadFile() {
        // set Title - Layout - Size
        setTitle("Demo ReadFile");
        setSize(350, 400);
        setLayout(null);
        // setLocationRelativeTo(rootPane);

        // Add TextField
        add(txtinput);
        txtinput.setBounds(20, 20, 200, 25);
        txtinput.setHorizontalAlignment(JTextField.RIGHT);

        // Add Button
        add(btnbrowse);
        btnbrowse.setBounds(230, 20, 80, 25);
        add(btnload);
        btnload.setBounds(20, 50, 90, 25);
        btnload.setEnabled(false);
        add(btnclear);
        btnclear.setBounds(115, 50, 90, 25);
        add(btnclearall);
        btnclearall.setBounds(210, 50, 100, 25);

        // Add Output
        add(scroll);
        scroll.setBounds(20, 85, 290, 200);
        txtoutput.setEditable(false);

        ActionListener clear = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent del) {
                // TODO Auto-generated method stub
                if (del.getSource() == btnclear) {
                    txtinput.setText("");
                } else {
                    if (del.getSource() == btnclearall) {
                        txtinput.setText("");
                        txtoutput.setText("");
                    }
                }
            }

        };
        btnclear.addActionListener(clear);
        btnclearall.addActionListener(clear);
       
        //Browse Action
        btnbrowse.addActionListener(new ActionListener() {
           
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                JFileChooser choose= new JFileChooser();
                choose.setMultiSelectionEnabled(false);
                int ichoose = choose.showOpenDialog(null);
                if(ichoose == JFileChooser.APPROVE_OPTION){
                    File open = choose.getSelectedFile();
                    txtinput.setText(open.getAbsolutePath());
                    btnload.setEnabled(true);
                }
                else{
                    txtinput.setText("");
                    btnload.setEnabled(false);
                }
            }
        });
        btnload.addActionListener(new ActionListener() {
           
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                try {
                    File open = new File(txtinput.getText());
                    Scanner readfile = new Scanner(open);
                    while (readfile.hasNextLine()) {
                        txtoutput.append(readfile.nextLine()+"
");
                           
                        }
                       
                        //txt2.append(readfile.nextLine() + "
");
                   
                    readfile.close();
                } catch (FileNotFoundException ex) {
                    txtoutput.append("Error: Can't open the file " + txtinput.getText()
                            + "
");
                }
               
            }
        });

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        DemoReadFile michael = new DemoReadFile();
        michael.setDefaultCloseOperation(EXIT_ON_CLOSE);
        michael.setVisible(true);

    }

}
đây là file test để dùng

- - - Nội dung đã được cập nhật ngày 19-11-2014 lúc 02:26 PM - - -

help...............