0
我试着做一个GUI程序,将采取两个文件,并比较其比较两个文件的JPanel
,以及它们是否符合其将显示匹配,如果没有它会显示两个文件的不同行。
我的问题是我将如何罚款两个文件 之间的不同线路以及如何在面板中打印结果?
public class Q25 extends JPanel implements ActionListener
{
File file1;
File file2;
JButton compare=new JButton("Compare");
JButton fileButton = new JButton("First File");
JButton fileButton1 = new JButton("Secound File");
JLabel labelA;
Q25()
{
add(fileButton);
add(fileButton1);
fileButton.addActionListener(this);
fileButton1.addActionListener(this);
add(compare);
labelA = new JLabel();
labelA.setText("\n\n\n\n result : ");
add(labelA);
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==fileButton)
{
JFileChooser chooser = new JFileChooser();
int option = chooser.showOpenDialog(Q25.this);
if (option == JFileChooser.APPROVE_OPTION)
{
if (!chooser.getSelectedFile().canRead())
JOptionPane.showMessageDialog(null,"The file is NOT readable by the current application!","ERROR" , JOptionPane.ERROR_MESSAGE);
}
}
if(e.getSource()==fileButton1)
{
JFileChooser chooser1 = new JFileChooser();
int option1 = chooser1.showOpenDialog(Q25.this);
if (option1 == JFileChooser.APPROVE_OPTION)
{
if (!chooser1.getSelectedFile().canRead())
JOptionPane.showMessageDialog(null, "The file is NOT readable by the current application!", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
if(file1==file2)
{
}else{
}
}
public static void main(String[]args)
{
JFrame frame1 = new JFrame("compare files ");
frame1.add(new Q25());
frame1.setLayout(new GridLayout());
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(250, 400);
frame1.setVisible(true);
}
}
你应该缩小你遇到的问题。一步一步解决问题。例如。首先确定两个文件是否相等,然后展开列出所有不同的行等。 – Paul