Hello!
Please help me!
I display the data from the arrylist xx in the table.
But the program shows the table several times.
I did not notice that before.
Now whenever I click the menu, it shows the table 26 times.
What is the problem? I am in trouble.
Please help me as soon as possible.
void jMenuItem5_actionPerformed(ActionEvent e) {if(irre.length()>5 && re.length()>5 ){ ArrayList xx=Sallsubobj1.theList; Collections.sort(xx, new columncomparator()); MyNode1 fl=new MyNode1(xx); fl.setSize(640, 390); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=fl.getSize(); fl.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); fl.setVisible(true); } }
import javax.swing.*;import javax.swing.border.*;import javax.swing.table.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.JOptionPane;public class MyNode1 extends JFrame{String []lptn=new String[]{"<subject> be noun",//1"<subject> passive-verb",//2"<subject> active-verb",//3"<subject> active-verb infinitive",//4"<subject> passive-verb infinitive",//5"noun be <obj>",//6"gerund <obj>",//7"infinitive <obj>",//8"active-verb infinitive <obj>",//9"passive-verb infinitive <obj>",//10"active-verb <obj>",//11"noun prep <np>",//12"passive-verb prep <np>",//13"active-verb prep <np>",//14"infinitive prep <np>"};//15 public ArrayList data; JPanel jPanel1 = new JPanel(); JButton jButton1 = new JButton(); class MyTableModel extends DefaultTableModel { MyTableModel(ArrayList p) { int i=0; this.addColumn("LinguisticPattern"); this.addColumn("TriggerVerb"); this.addColumn("RelevantConunt"); this.addColumn("IrrelevantCount"); this.addColumn("TotalCount"); this.addColumn("RelevantRate"); this.addColumn("Rank"); while(i<data.size()) { { Object[] obj=new Object[7]; obj[0]=lptn[((Crules)p.get(i)).lp-1]; obj[1]=((Crules)p.get(i)).tri; obj[2]=""+((int)(((Crules)p.get(i)).count)); obj[3]=""+(int)(((Crules)p.get(i)).count1); obj[4]=""+(int)(((Crules)p.get(i)).totalcount); obj[5]=""+(double)((Crules)p.get(i)).relrate; obj[6]=""+(double)((Crules)p.get(i)).rank; this.addRow(obj); } i++; } } } public MyNode1( ArrayList data) { super("RuleGen");this.data=data; MyTableModel tm=new MyTableModel(data); final JTable jt=new JTable(tm); JScrollPane jsp=new JScrollPane(jt); Container c=this.getContentPane(); c.add(jsp,BorderLayout.CENTER); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setContentPane(c); } public MyNode1() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { this.getContentPane().setLayout(null); jPanel1.setBounds(new Rectangle(1, 370, 518, 43)); jPanel1.setLayout(null); jButton1.setText("Sort"); jButton1.setBounds(new Rectangle(191, 17, 115, 20)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); this.getContentPane().add(jPanel1, null); jPanel1.add(jButton1, null); } void jButton1_actionPerformed(ActionEvent e) {Collections.sort(data, new columncomparator());MyNode1 f2=new MyNode1(data);f2.setSize(640, 390);f2.jButton1.setText("OK");Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();Dimension frameSize=f2.getSize();f2.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);f2.setVisible(true);this.dispose(); }}