Below is my full code, it compiles properly within the eclipse IDE, but when I try and export it as a runnable JAR file, it says it exported with errors. Then When I try to run the Jar file, none of the labels or text fields show up, nor does my event handler on the button work. I'm not sure what to change since it compiled properly before it was exported.
public class TaskFrame extends JFrame implements ActionListener {
private JPanel taskPanel, buttonPanel, viewPanel, titlePanel;
private JButton editButton;
private String[] labelNames = {"Notes", "Paging", "Event Mgmt - Early", "Event Mgmt - Late", "Airhub 2DA",
"Airhub 1DA", "GSSD", "GSSI", "GSSRR", "Holdovers", "Radio", "PTI", "Phones 1300", "Publishing"};
private JLabel[] labelArray = new JLabel[labelNames.length];
private JLabel titleLabel = new JLabel("Task Dashboard");
private JTextField[] textArray = new JTextField[labelNames.length];
private String[] namesArray = new String[labelNames.length];
private Font titleFont = new Font("Helvetica", Font.BOLD, 24);
private Color backgroundColor = new Color(255,250,245);
@Override
public void actionPerformed(ActionEvent arg0) {
}
public static void main(String[] args) {
TaskFrame frame = new TaskFrame();
frame.setTitle("Task List");
frame.setSize(300, 450);
frame.setResizable(false);
frame.setVisible(true);
}
public TaskFrame() {
//Create the locked task panel
taskPanel = new JPanel(new GridLayout(14,2,1,2));
buttonPanel = new JPanel(new FlowLayout());
titlePanel = new JPanel(new FlowLayout());
titleLabel.setFont(titleFont);
titlePanel.add(titleLabel, SwingConstants.CENTER);
viewPanel = new JPanel(new FlowLayout());
//create the button object and assign the event handler
editButton = new JButton("Edit Tasks");
editButton.setPreferredSize(new Dimension(100,25));
editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!textArray[0].isEditable()) {
for(int i = 0; i < labelNames.length; i++) {
textArray[i].setEditable(true);
}
editButton.setText("Save Tasks");
} else {
try {
PrintWriter writeNames = new PrintWriter("Techs.txt", "UTF-8");
for(int i = 0; i < labelNames.length; i ++) {
writeNames.println(textArray[i].getText());
textArray[i].setEditable(false);
}
writeNames.close();
} catch (FileNotFoundException e1) {
e1.getMessage();
} catch (UnsupportedEncodingException e1) {
e1.getMessage();
}
}
}
});
buttonPanel.add(editButton);
//Loop to create all the viewPanel objects, JLabels and JTextFields
try {
FileReader fr = new FileReader("Techs.txt");
BufferedReader br = new BufferedReader(fr);
for(int i = 0; i < labelNames.length; i++) {
labelArray[i] = new JLabel(labelNames[i] + ": ", SwingConstants.LEFT);
textArray[i] = new JTextField(10);
namesArray[i] = new String();
namesArray[i] = br.readLine();
textArray[i].setText(namesArray[i]);
textArray[i].setEditable(false);
taskPanel.add(labelArray[i]);
taskPanel.add(textArray[i]);
}
} catch (FileNotFoundException e1) {
e1.getMessage();
} catch (IOException e1) {
e1.getMessage();
}
//Assign the defined background color to all panels
titlePanel.setBackground(backgroundColor);
taskPanel.setBackground(backgroundColor);
buttonPanel.setBackground(backgroundColor);
viewPanel.setBackground(backgroundColor);
viewPanel.add(titlePanel, BorderLayout.NORTH);
viewPanel.add(taskPanel, BorderLayout.CENTER);
viewPanel.add(buttonPanel, BorderLayout.SOUTH);
add(viewPanel);
viewPanel.setVisible(true);
}
}