GUI not appearing when i run file?
First of all i will let you know that i am using the NetBeans IDE 5.0
I have part written a program that will allow a user to store information about the company cars, it will store a range of data, but i have hit a snag. When i build my main project, it builds successfully, but the GUI does not appear on screen.
I tried going to "Run" and then "frmCars.java", at the bottom in the output window it says it was done successfully, but i do not see the GUI on screen?
I don't want people to do the work for me, but i would like some advice on why it is not showing the GUI, as i was just about to test the "New" button to make sure it successfully creates the file.
At the minute i have 3 documents:
Main.java
carRecords.java (class)
frmCars (form/gui)
code for Main.java
package carcalculator;
/**
*
* @author Daniel
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
code for carRecords.java
package carcalculator;
/**
*
* @author Daniel Harris
*/
import java.io.*;
public class carRecords implements Serializable{
private String regNo;
private String description;
private double runningCost;
private float annualInsurance;
private String department;
/** Creates a new instance of VideoRecord */
public carRecords() {
this("","",0,0,"");
}
public carRecords(String r, String d,double c,float i,String m){
setRegNo(r);
setDescription(d);
setRunningCost(c);
setAnnualInsurance(i);
setDepartment(m);
}
public void setRegNo(String r){
regNo = r;
}
public String getRegNo(){
return regNo;
}
public void setDescription(String d){
description =d;
}
public String getDescription(){
return description;
}
public void setRunningCost(double c){
runningCost = c;
}
public double getRunningCost(){
return runningCost;
}
public void setAnnualInsurance(float i){
annualInsurance = i;
}
public float getAnnualInsurance(){
return annualInsurance;
}
public void setDepartment(String m){
department = m;
}
public String getDepartment(){
return department;
}
}
# 1 Re: GUI not appearing when i run file?
code for frmCars.java
package carcalculator;
import java.io.*;
import javax.swing.*;
/**
*
* @author Daniel
*/
public class frmCars extends javax.swing.JPanel {
ObjectOutputStream output;
ObjectInputStream input;
File file = new File(new File(getClass().getResource("dataFiles").getFile()),"cars.txt");
/** Creates new form frmCars */
public frmCars() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jFrame1 = new javax.swing.JFrame();
txtRegNo = new javax.swing.JTextField();
txtDescription = new javax.swing.JTextField();
txtRunningCost = new javax.swing.JTextField();
txtAnnualInsurance = new javax.swing.JTextField();
txtDepartment = new javax.swing.JTextField();
cmdNew = new javax.swing.JButton();
cmdAdd = new javax.swing.JButton();
cmdFirst = new javax.swing.JButton();
cmdNext = new javax.swing.JButton();
org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
txtRegNo.setText("enterreg");
txtDescription.setText("enterdesc");
txtRunningCost.setText("enterrunningcost");
txtAnnualInsurance.setText("enterinsurance");
txtDepartment.setText("enterdepartment");
cmdNew.setText("New");
cmdNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdNewActionPerformed(evt);
}
});
cmdAdd.setText("Add");
cmdFirst.setText("First");
cmdNext.setText("Next");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(145, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(cmdNew)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cmdAdd)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cmdFirst)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cmdNext))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(txtDescription)
.add(txtRunningCost)
.add(txtAnnualInsurance)
.add(txtRegNo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
.add(txtDepartment)))
.add(25, 25, 25))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(35, 35, 35)
.add(txtRegNo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtDescription, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtRunningCost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtAnnualInsurance, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtDepartment, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(cmdNew)
.add(cmdAdd)
.add(cmdFirst)
.add(cmdNext))
.addContainerGap(100, Short.MAX_VALUE))
);
}// </editor-fold>
private void cmdNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
output = new ObjectOutputStream(new FileOutputStream(file));
}
catch (IOException e){
JOptionPane.showMessageDialog(this, "File Not Found!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
frmCars gui = new frmCars () ;
gui.show(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton cmdAdd;
private javax.swing.JButton cmdFirst;
private javax.swing.JButton cmdNew;
private javax.swing.JButton cmdNext;
private javax.swing.JFrame jFrame1;
private javax.swing.JTextField txtAnnualInsurance;
private javax.swing.JTextField txtDepartment;
private javax.swing.JTextField txtDescription;
private javax.swing.JTextField txtRegNo;
private javax.swing.JTextField txtRunningCost;
// End of variables declaration
}
In the document frmCars.java the following lines were not present automatically in the file:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
frmCars gui = new frmCars () ;
gui.show(true);
}
});
}
But without them i was getting the error:
Class "carcalculator.frmCars" does not have a main method
By the way i am only a beginner when it comes to java, but i have been at this for hours and i really can't figure it out :(
Many Thanks,
Dan