Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I test my code in another class?
    primarykey
    data
    text
    <p>I want to test my code by running it as an instance in another class, but nothing happens. I have been able to do this in the past, but this time I can't get it to work. I think I'm just missing something simple, but can't figure it out. I'm sorry that this problem is probably unique to me, but I'm desperate for help on this and running out of time. Thanks</p> <p>This is the code from my main class</p> <pre><code>package minorb; import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import java.util.*; public class TableAddRows extends JFrame implements ActionListener { // Variables ------------------------------------------------------------- double percOne = (0.1); double percTwo = (0.4); double percThree = (0.2); double percFour = (0.3); private JTable table; private JButton addRow; StudentManagement r = new StudentManagement(); ArrayList&lt;String&gt; stu = new ArrayList&lt;String&gt;(); // Methods --------------------------------------------------------------- public void TableAddRows() { this.getContentPane(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); r.openFile(); r.readFile(); for(String s: stu) { String[] line = s.split(","); String[] tableCol = { "Name", "FAN", "Score 1", "Score 2", "Score 3", "Score 4", "Final Score", "Grade" }; Object[][] data = { { line[0], line[1],Double.parseDouble(line[2]),Double.parseDouble(line[3]), + Double.parseDouble(line[4]),Double.parseDouble(line[5]), + Double.parseDouble(line[2])*(percOne) + Double.parseDouble(line[3])*(percTwo)+ Double.parseDouble(line[4])*(percThree) + Double.parseDouble(line[5])*(percFour) }, {}, {} }; table = new JTable(new DefaultTableModel(data, tableCol)); addRow = new JButton("Add Row"); addRow.addActionListener(this); Container cp = getContentPane(); cp.add(new JScrollPane(table)); cp.add(addRow, BorderLayout.SOUTH); pack(); this.setVisible(true); } } public void actionPerformed(ActionEvent ev) { if (ev.getSource() == addRow) { DefaultTableModel model = (DefaultTableModel) table.getModel(); if (model.getRowCount() &lt; 10) { model.addRow(new Object[] {}); } } } public void pen () { new TableAddRows(); } } </code></pre> <p>This is the code I've used to try to run it from the other class</p> <pre><code>package minorb; public class Minorb { public static void main(String[] args) { StudentManagement r = new StudentManagement(); TableAddRows s = new TableAddRows(); s.TableAddRows(); } } </code></pre> <p>Netbeans found no errors with the code Also the basic idea of this application is to read a txt file and display that data into a table</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload