I have problems with choosing a line and to find a number or times specifif word repeats in that line?
Can you help me with that?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DefectInspector
{
private JFrame frame = new JFrame();
private JPanel p1,p2,p3,p4;
private JMenuBar jmb;
private JMenu jmFile;
private JMenuItem jmiOpen, jmiExit;
private JLabel jlRow;
private JTextField jtfRow;
private JTextArea area;
private JButton jbInspect;
private JScrollPane jsp;
public DefectInspector()
{
jmb = new JMenuBar();
frame.setJMenuBar(jmb);
jmFile = new JMenu("File");
jmb.add(jmFile);
jmiOpen = new JMenuItem("Open");
jmiExit = new JMenuItem("Exit");
jmFile.add(jmiOpen);
jmFile.add(jmiExit);
p1 = new JPanel();
p1.setLayout(new FlowLayout());
jlRow = new JLabel("Row: ");
jtfRow = new JTextField(15);
jtfRow.setEditable(false);
p1.add(jlRow);
p1.add(jtfRow);
p2 = new JPanel();
p2.setLayout(new BorderLayout());
area = new JTextArea(0,0);
area.setEditable(false);
area.setLineWrap(true);
area.setWrapStyleWord(true);
jsp = new JScrollPane(area);
p2.add(jsp, "Center");
p3 = new JPanel();
p3.setLayout(new FlowLayout());
jbInspect = new JButton("Inspect");
p3.add(jbInspect);
p4 = new JPanel();
p4.setLayout(new BorderLayout());
p4.add(p1, "North");
p4.add(p2, "Center");
p4.add(p3, "South");
frame.add(p4);
DefectListener listener = new DefectListener(jmiOpen, jmiExit, jtfRow, area, jbInspect);
jmiOpen.addActionListener(listener);
jmiExit.addActionListener(listener);
jtfRow.addActionListener(listener);
jbInspect.addActionListener(listener);
frame.setTitle("Defect Inspector");
frame.setSize(300,300);
frame.setLocation(200,200);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[]args)
{
new DefectInspector();
}
}
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class DefectListener implements ActionListener
{
private JMenuItem jmiOpen, jmiExit;
private JTextField jtfRow;
private JTextArea area;
private JButton jbInspect;
private int numberRows = 0;
private JFrame frame;
//private File file = new File("data.txt");;
private LineNumberReader lnr = null;
//private file = new File("student.csv");
// file readers
//private FileReader fr = new FileReader("data.txt");
// private BufferedReader in = new BufferedReader(fr);
// private ArrayList <String> lines = new ArrayList<String>();
public DefectListener(JMenuItem jmiOpen, JMenuItem jmiExit, JTextField jtfRow, JTextArea area, JButton jbInspect)
{
this.jmiOpen = jmiOpen;
this.jmiExit = jmiExit;
this.jtfRow = jtfRow;
this.area = area;
this.jbInspect = jbInspect;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jmiOpen)
{
try{
FileReader fr = new FileReader("data.txt");
BufferedReader in = new BufferedReader(fr);
String line = null;
while((line = in.readLine()) != null)
{
area.append(line +"\n");
//lines.add(line);
}
in.close();
area.setEditable(true);
jtfRow.setEditable(true);
}
catch(FileNotFoundException fnf)
{
JOptionPane.showMessageDialog(null, "File not found");
}
catch(IOException ioe)
{
System.out.println("IO error detected");
}
}
else if(e.getSource() == jmiExit)
{
System.exit(1);
}
else if(e.getSource() == jbInspect)
{
try{
String value = jtfRow.getText();
numberRows = Integer.parseInt(value);
String linN = area.getText();
//String selectedLine = get
//lnr = new LineNumberReader(fr);
//area.setLineNumber(numberRows);
JOptionPane.showMessageDialog(null, "The number is: ","about",JOptionPane.INFORMATION_MESSAGE);
}
catch (NumberFormatException n)
{
System.out.println("BUUUU");
}
}
}
}