Hi!
I'm converting an application which was initally text based to one with a GUI.
I'm encountering a few problems and wondered if anyone could help.
package airshipMuseum;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
* Airship museum application - Stores information about airships stored in a
* museum
*
* @author mn
* @version 1.0
*/
public class AirshipMuseumApplication extends javax.swing.JFrame {
/**
* Variable to store an instance of Museum
*/
private Museum museum;
private JPanel jPanelButtonContainer;
private JButton jButtonAdd;
private JButton jButtonSearch;
private JButton jButtonList;
private JButton jButtonArchive;
private JButton jButtonExhibit;
private JButton jButtonDelete;
// add a reference to this frame
private JFrame mainWindow;
/**
* ID of the airship to be deleted, set to exhibit or to archive
*/
public int ID;
/**public void run() {
museum = new Museum(); // create an instance of Museum
}*/
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
new AirshipMuseumApplication();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
AirshipMuseumApplication inst = new AirshipMuseumApplication();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
//museum = new Museum();
//TODO fix: create instance of museum - CRITICAL!
//TODO load persistent airships (invisible to user)
}
//new AirshipMuseumApplication().run();
});
}
/**
* AirshipMuseumApplication constructor
* @param none
*/
public AirshipMuseumApplication() {
super();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//TODO save airships from array to file
mainWindow = this;
initGUI();
}
private void initGUI() {
try {
{
this.setTitle("Airship Museum");
}
{
jPanelButtonContainer = new JPanel();
GridLayout jPanel1Layout = new GridLayout(2, 3);
jPanel1Layout.setColumns(2);
jPanel1Layout.setRows(3);
jPanel1Layout.setHgap(20);
jPanel1Layout.setVgap(20);
getContentPane()
.add(jPanelButtonContainer, BorderLayout.CENTER);
jPanelButtonContainer.setLayout(jPanel1Layout);
{
jButtonAdd = new JButton();
jPanelButtonContainer.add(jButtonAdd);
jButtonAdd.setText("Add Airship");
jButtonAdd
.setPreferredSize(new java.awt.Dimension(233, 85));
jButtonAdd.setMnemonic(java.awt.event.KeyEvent.VK_A);
jButtonAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// TODO add your code for jButtonAdd.actionPerformed
AddAirshipDialog dialog = new AddAirshipDialog(
mainWindow);
}
});
}
{
jButtonDelete = new JButton();
jPanelButtonContainer.add(jButtonDelete);
jButtonDelete.setText("Delete Airship");
jButtonDelete.setMnemonic(java.awt.event.KeyEvent.VK_D);
jButtonDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ID = Integer.parseInt(
JOptionPane.showInputDialog("Enter ID of the airship you would like to delete: "));
int result = JOptionPane.showConfirmDialog(null, "Are you sure?");
switch (result){
case JOptionPane.OK_OPTION :
// delete this airship
museum.deleteAirship(ID);
JOptionPane.showMessageDialog(null, "Airship successfully deleted");
break;
case JOptionPane.CANCEL_OPTION :
// do nothing
break;
}
}
}
);
}
{
jButtonExhibit = new JButton();
jPanelButtonContainer.add(jButtonExhibit);
jButtonExhibit.setText("Exhibit Airship");
jButtonExhibit.setMnemonic(java.awt.event.KeyEvent.VK_E);
jButtonExhibit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ID = Integer.parseInt(
JOptionPane.showInputDialog("Enter ID of the airship you would like to exhibit: "));
int result = JOptionPane.showConfirmDialog(null, "Are you sure?");
switch (result){
case JOptionPane.OK_OPTION :
// exhibit this airship
museum.exhibitAirship(ID);
JOptionPane.showMessageDialog(null, "Airship successfully set to exhibit");
break;
case JOptionPane.CANCEL_OPTION :
// do nothing
break;
}
}
}
);
}
{
jButtonArchive = new JButton();
jPanelButtonContainer.add(jButtonArchive);
jButtonArchive.setText("Archive Airship");
jButtonArchive.setMnemonic(java.awt.event.KeyEvent.VK_R);
jButtonArchive.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ID = Integer.parseInt(
JOptionPane.showInputDialog("Enter ID of the airship you would like to archive: "));
int result = JOptionPane.showConfirmDialog(null, "Are you sure?");
switch (result){
case JOptionPane.OK_OPTION :
// archive this airship
museum.returnAirship(ID);
JOptionPane.showMessageDialog(null, "Airship successfully archived");
break;
case JOptionPane.CANCEL_OPTION :
// do nothing
break;
}
}
}
);
}
{
jButtonList = new JButton();
jPanelButtonContainer.add(jButtonList);
jButtonList.setText("List Airships...");
jButtonList.setMnemonic(java.awt.event.KeyEvent.VK_L);
jButtonList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//TODO show list frame
ListAirships JFrame = new ListAirships();
JFrame.setVisible(true);
}
});
}
{
jButtonSearch = new JButton();
jPanelButtonContainer.add(jButtonSearch);
jButtonSearch.setText("Search Airships");
jButtonSearch.setMnemonic(java.awt.event.KeyEvent.VK_S);
jButtonSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ID = Integer.parseInt(
JOptionPane.showInputDialog("Enter the manufacturer of airship you would like to search: "));
//TODO show how many were found, open list
//JOptionPane.showMessageDialog(null, "Airship successfully archived");
}
}
);
}
}
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
I cannot figure out how to create an instance of museum.
Before, when it was text based I had this:
public static void main(String [] args) {
new MuseumApplication().run();
}
}
and this:
public void run() {
museum = new Museum();
}
but now i'm using jigloo it's added all that other stuff which I don't understand!
Thankyou for looking