这是我删除的其他不需要的代码你现在可以运行吗???如果您能运行此程序并告诉我我错的部分,我将不胜感激。这是我的决赛项目我不知道我将如何做下一个和上一个按钮。所以我特别咨询了这个网站
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
public class dadas implements ActionListener {
static String summary,summary2,summary3;
JFrame frame=new JFrame("Generator X");
JPanel p = new JPanel();
JLabel studentno=new JLabel("Student No:");
JLabel name= new JLabel("First name:");
JLabel lastname= new JLabel("Last Name:");
JTextField number= new JTextField();
JTextField name2= new JTextField();
JTextField lastname2= new JTextField();
JButton next=new JButton("NEXT---->");
JButton prev=new JButton("<----PREV");
JButton add=new JButton("Add");
JButton save=new JButton("Save");
public static void main(String args[]) {
new dadas();
}
public dadas(){
frame.setSize(300,500);//frame
frame.setLayout(null);
frame.setVisible(true);
frame.setResizable(false);
studentno.setBounds(30,30,80,60);//LABEL
number.setBounds(100,45,100,25);//TextField
number.addActionListener(this);
number.setDocument(new JTextFieldLimit(7));
number.setEditable(false);
name.setBounds(30,70,100,65);//LABEL
name2.setBounds(100,90,100,28);//TextField
name2.addActionListener(this);
name2.setEditable(false);
lastname.setBounds(30,115,100,65);//LABEL
lastname2.setBounds(100,133,120,28);//TextField
lastname2.addActionListener(this);
lastname2.setEditable(false);
next.setBounds(150,170,100,30);//Next Button
next.addActionListener(this);
prev.setBounds(50,170,100,30);//Previous Button
prev.addActionListener(this);
add.setBounds(50,210,100,30);
add.addActionListener(this);
save.setBounds(100,250,100,30);//Save Button
save.addActionListener(this);
frame.add(studentno);
frame.add(name);
frame.add(lastname);
frame.add(number);
frame.add(name2);
frame.add(lastname2);
frame.add(next);
frame.add(prev);
frame.add(add);
frame.add(save);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==add){
number.setEditable(true);
name2.setEditable(true);
lastname2.setEditable(true);
next.setEnabled(false);
prev.setEnabled(false);
}
else if( e.getSource()==save ){//save button
summary = (" "+number.getText()) ;
summary2 = ("" +name2.getText()) ;
summary3 = (" "+lastname2.getText());
String I = dadas.summary;
String Love = dadas.summary2;
String You = dadas.summary3;
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(newFile("C:\\lol.txt"),true));
bw.write(I);
bw.newLine();
bw.close();
JOptionPane.showMessageDialog(frame,"Your File has been Saved");
}
catch(IOException E)
{
}
}
else if(e.getSource()==next){//Next Button
try {
String filePath = "C:\\lol.txt";
BufferedReader br = new BufferedReader(new FileReader(filePath));//my file Writer
String file;
while((file = br.readLine()) != null){
number.setText(file);
lastname2.setText(file);
name2.setText(file);
}
br.close();
}catch(IOException ex) {
ex.printStackTrace();
}
}
}
}