Vote count:
0
I have created a java swing app and made a runnable jar using eclipse.
The main class leads to a login page, where there is a text and password field used to verify login details. The code for this page is below:
public class LoginPage extends Toolbar{
public static int WIDTH = 1200;
public static final int HEIGHT = 700;
public static JFrame frame = new JFrame();
private static JTextField UsernameWrite;
public static void LoginPageGui(){
JPanel UsernamePanel = new JPanel(new FlowLayout());
JTextField UsernameRead = new JTextField("Username");
UsernameRead.setHorizontalAlignment(JTextField.CENTER);
FieldSetup(UsernameRead,170, 35, "Username", Color.WHITE, false);
final JTextField UsernameWrite = new JTextField();
FieldSetup(UsernameWrite,170, 35, "", Color.WHITE, true);
UsernamePanel.add(UsernameRead);
UsernamePanel.add(UsernameWrite);
JPanel PasswordPanel = new JPanel(new FlowLayout());
JTextField PasswordRead = new JTextField("Password");
PasswordRead.setHorizontalAlignment(JTextField.CENTER);
FieldSetup(PasswordRead,170, 35, "Password", Color.WHITE, false);
final JPasswordField PasswordWrite = new JPasswordField();
FieldSetup(PasswordWrite,170, 35, "", Color.WHITE, true);
PasswordPanel.add(PasswordRead);
PasswordPanel.add(PasswordWrite);
JPanel ButtonPanel = new JPanel();
JButton ButtonLogin = new JButton("Login");
FieldSetup(ButtonLogin, 350,35);
ButtonLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
char[] a = PasswordWrite.getPassword();
String b = UsernameWrite.getText();
String aa = null;
if(a.length==6){
aa= String.copyValueOf(a);
if(aa.equals("LeeFeb") && b.equals("LeeWalker")){
Date dt = new Date();
String newDate = Calendar.EditDate(dt.toString());
WorkDiary.WorkDiaryGui(newDate);
Customers.framesize();
}
else{
JOptionPane.showMessageDialog(null,"Incorrect Login Details");
PasswordWrite.setText("");
}
}
else{
JOptionPane.showMessageDialog(null,"Incorrect Login Details");
PasswordWrite.setText("");
}
}
});
ButtonPanel.add(ButtonLogin);
JPanel Panels = new JPanel(new BorderLayout());
Panels.add(UsernamePanel, BorderLayout.NORTH);
Panels.add(PasswordPanel);
JPanel All = new JPanel(new BorderLayout());
All.add(Panels,BorderLayout.NORTH);
All.add(ButtonPanel);
JPanel Screen = new JPanel(new GridBagLayout());
Screen.add(All);
Customers.frameGui(Screen, "Login Page");
}
public static void FieldSetup(JTextField field, int x, int y, String text, Color color, Boolean Editable){
field.setText(text);
field.setBackground(color);
field.setPreferredSize(new Dimension(x, y));
field.setEditable(Editable);
Border border = BorderFactory.createLineBorder(Color.BLACK);
if(Editable==true){
field.setBorder(border);
}
}
public static void FieldSetup(JPasswordField field, int x, int y, String text, Color color, Boolean Editable){
field.setBackground(color);
field.setPreferredSize(new Dimension(x, y));
field.setEditable(Editable);
Border border = BorderFactory.createLineBorder(Color.BLACK);
field.setBorder(border);
}
public static void FieldSetup(JButton button, int x, int y){
button.setPreferredSize(new Dimension(x, y));
button.setMaximumSize(new Dimension(x, y));
button.setMinimumSize(new Dimension(x, y));
Border border = BorderFactory.createLineBorder(Color.BLACK);
button.setBorder(border);
}
}
The login page leads to todays diary, the code for that page is below:
public class WorkDiary extends Toolbar{
Color Background;
static JTextField Singlejobid = new JTextField();
static JTextField Singledate = new JTextField();
static JTextField Singleregistration = new JTextField();
static JTextField singlesurname= new JTextField();
static JTextField singlephone= new JTextField();
static JTextField Singlemake = new JTextField();
static JTextField Singlemodel = new JTextField();
static JTextField Singlenotes = new JTextField();
public static void WorkDiaryGui(String Date){
UIManager.put("OptionPane.cancelButtonText", "Cancel");
UIManager.put("OptionPane.okButtonText", "Ok");
Customers.Edit=false;
Customers.Delete=false;
JPanel ToolBar = new JPanel();
ToolBar.add(Toolbar.Toolbar("Diary"));
JPanel Table = new JPanel();
Table.add(WorkDiaryTableHeadings(Table));
DbHandlerWorkDiary.WorkDiarySelectWhere(Table, Date);
JPanel All = new JPanel(new BorderLayout());
All.add(ToolBar, BorderLayout.PAGE_START);
All.add(Table);
Customers.frameGui(All, "Diary");
}
public static void AddWorkDiaryGui(int JobID, String Date, int CustID, String Registration){
UIManager.put("OptionPane.cancelButtonText", "Cancel");
UIManager.put("OptionPane.okButtonText", "Ok");
Customers.Edit=false;
Customers.Delete=false;
JPanel ToolBar = new JPanel();
ToolBar.add(Toolbar.Toolbar("Add Job"));
JPanel Table = new JPanel();
Table.add(WorkDiaryTableHeadings(Table));
String Custentries[]=new String[2];
Custentries = DbHandlerCustomers.CustomersReturnSurnameAndPhone(CustID);
String Carentries[]=new String[2];
Carentries = DbHandlerCars.CarsReturnMakeAndModel(Registration);
Table.add(WorkDiaryTableSingle(Integer.toString(JobID),Date,Registration,Custentries[1], Custentries[0], Carentries[0], Carentries[1], "", true, Table ));
JPanel All = new JPanel(new BorderLayout());
All.add(ToolBar, BorderLayout.PAGE_START);
All.add(Table);
Customers.frameGui(All, "Add Job");
}
public static void EditWorkDiaryGui(int JobId){
UIManager.put("OptionPane.cancelButtonText", "Cancel");
UIManager.put("OptionPane.okButtonText", "Ok");
Customers.Edit=false;
Customers.Delete=false;
JPanel ToolBar = new JPanel();
ToolBar.add(Toolbar.Toolbar("Edit Job"));
JPanel Table = new JPanel();
Table.add(WorkDiaryTableHeadings(Table));
DbHandlerWorkDiary.WorkDiarySelectWhere(Table, JobId);
JPanel All = new JPanel(new BorderLayout());
All.add(ToolBar, BorderLayout.PAGE_START);
All.add(Table);
Customers.frameGui(All, "Edit Job");
}
public static void WorkDiarySearchResGui(int numbers, String letters){
UIManager.put("OptionPane.cancelButtonText", "Cancel");
UIManager.put("OptionPane.okButtonText", "Ok");
Customers.Edit=false;
Customers.Delete=false;
JPanel ToolBar = new JPanel();
ToolBar.add(Toolbar.Toolbar("Search Jobs"));
JPanel Table = new JPanel();
Table.add(WorkDiaryTableHeadings(Table));
if(numbers==-1){
int counter = DbHandlerWorkDiary.WorkDiarySelectWhereLetters(Table, letters);
if(counter==0){
JOptionPane.showMessageDialog(null,"No Entry Found");
return;
}
}
if(letters==null){
int counter = DbHandlerWorkDiary.WorkDiarySelectWhereNumbers(Table, numbers);
if(counter==0){
JOptionPane.showMessageDialog(null,"No Entry Found");
return;
}
}
if(letters!=null && numbers!=-1){
int counter = DbHandlerWorkDiary.WorkDiarySelectWhereNumbers(Table, numbers);
int counter1 = DbHandlerWorkDiary.WorkDiarySelectWhereLetters(Table, letters);
if(counter==0 && counter1==0){
JOptionPane.showMessageDialog(null,"No Entry Found");
return;
}
}
JPanel All = new JPanel(new BorderLayout());
All.add(ToolBar, BorderLayout.PAGE_START);
All.add(Table);
Customers.frameGui(All, "Search Jobs");
}
public static JPanel WorkDiaryTable(String JobID, String Date, String Registration, String Surname, String Phone, String Make, String Model, String Notes, Boolean Editable, JPanel panel){
FlowLayout FlowWorkDiaryTable = (FlowLayout)panel.getLayout();
FlowWorkDiaryTable.setHgap(0);
FlowWorkDiaryTable.setVgap(0);
JPanel WorkDiaryTable = new JPanel(FlowWorkDiaryTable);
JButton jobID = new JButton(JobID);
JButton date = new JButton(Date);
JButton registration = new JButton(Registration);
JButton surname = new JButton(Surname);
JButton phone = new JButton(Phone);
JButton make = new JButton(Make);
JButton model = new JButton(Model);
JButton notes = new JButton(Notes);
FieldSetup(jobID, 80, 25, JobID, Color.WHITE, Editable, JobID, Registration);
FieldSetup(date, 120, 25, Date, Color.WHITE, Editable, JobID, Registration);
FieldSetup(registration, 120, 25, Registration, Color.WHITE, Editable, JobID, Registration);
FieldSetup(surname, 120, 25, Surname, Color.WHITE, Editable, JobID, Registration);
FieldSetup(phone, 120, 25, Phone, Color.WHITE, Editable, JobID, Registration);
FieldSetup(make, 120, 25, Make, Color.WHITE, Editable, JobID, Registration);
FieldSetup(model, 120, 25, Model, Color.WHITE, Editable, JobID, Registration);
FieldSetup(notes, 300, 25, Notes, Color.WHITE, Editable, JobID, Registration);
WorkDiaryTable.add(jobID);
WorkDiaryTable.add(date);
WorkDiaryTable.add(registration);
WorkDiaryTable.add(surname);
WorkDiaryTable.add(phone);
WorkDiaryTable.add(make);
WorkDiaryTable.add(model);
WorkDiaryTable.add(notes);
return WorkDiaryTable;
}
public static JPanel WorkDiaryTableSingle(String JobID, String date, String registration, String surname, String phone, String make, String model, String notes,Boolean Editable, JPanel panel){
FlowLayout FlowWorkDiaryTable = (FlowLayout)panel.getLayout();
FlowWorkDiaryTable.setHgap(0);
FlowWorkDiaryTable.setVgap(0);
JPanel WorkDiaryTable = new JPanel(FlowWorkDiaryTable);
FieldSetup(Singlejobid, 80, 25, JobID, Color.WHITE, false);
FieldSetup(Singledate, 120, 25, date, Color.WHITE, false);
FieldSetup(Singleregistration, 120, 25, registration, Color.WHITE, false);
FieldSetup(singlesurname, 120, 25, surname, Color.WHITE, false);
FieldSetup(singlephone, 120, 25, phone, Color.WHITE, false);
FieldSetup(Singlemake, 120, 25, make, Color.WHITE, false);
FieldSetup(Singlemodel, 120, 25, model, Color.WHITE, false);
FieldSetup(Singlenotes, 300, 25, notes, Color.WHITE, Editable);
WorkDiaryTable.add(Singlejobid);
WorkDiaryTable.add(Singledate);
WorkDiaryTable.add(Singleregistration);
WorkDiaryTable.add(singlesurname);
WorkDiaryTable.add(singlephone);
WorkDiaryTable.add(Singlemake);
WorkDiaryTable.add(Singlemodel);
WorkDiaryTable.add(Singlenotes);
return WorkDiaryTable;
}
public static JPanel WorkDiaryTableHeadings(JPanel panel){
FlowLayout FlowWorkDiaryTable = (FlowLayout)panel.getLayout();
FlowWorkDiaryTable.setHgap(0);
FlowWorkDiaryTable.setVgap(0);
Font font = new Font("Courier", Font.BOLD,12);
JPanel WorkDiary = new JPanel(FlowWorkDiaryTable);
JTextField JobID = new JTextField();
FieldSetup(JobID, 80, 25, " Job ID", Color.CYAN, false);
JobID.setFont(font);
JTextField JobDate = new JTextField();
FieldSetup(JobDate, 120, 25, " Date", Color.CYAN, false);
JobDate.setFont(font);
JTextField registration = new JTextField();
FieldSetup(registration, 120, 25, " Registration", Color.CYAN, false);
registration.setFont(font);
JTextField surname = new JTextField();
FieldSetup(surname, 120, 25, " Surname", Color.CYAN, false);
surname.setFont(font);
JTextField phone = new JTextField();
FieldSetup(phone, 120, 25, " Phone", Color.CYAN, false);
phone.setFont(font);
JTextField make = new JTextField();
FieldSetup(make, 120, 25, " Make", Color.CYAN, false);
make.setFont(font);
JTextField model = new JTextField();
FieldSetup(model, 120, 25, " Model", Color.CYAN, false);
model.setFont(font);
JTextField notes = new JTextField();
FieldSetup(notes, 300, 25, " Notes", Color.CYAN, false);
notes.setFont(font);
WorkDiary.add(JobID);
WorkDiary.add(JobDate);
WorkDiary.add(registration);
WorkDiary.add(surname);
WorkDiary.add(phone);
WorkDiary.add(make);
WorkDiary.add(model);
WorkDiary.add(notes);
return WorkDiary;
}
public static void FieldSetup(JTextField field, int x, int y, String text, Color color, Boolean Editable){
field.setText(text);
field.setBackground(color);
field.setPreferredSize(new Dimension(x, y));
field.setEditable(Editable);
Border border = BorderFactory.createLineBorder(Color.BLACK);
field.setBorder(border);
}
public static void FieldSetup(JButton button, int x, int y, String text, Color color, Boolean Editable, final String JobID, final String Registration){
button.setText(text);
button.setBackground(color);
button.setPreferredSize(new Dimension(x, y));
Border border = BorderFactory.createLineBorder(Color.BLACK);
button.setBorder(border);
button.setName(JobID);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(Customers.Edit==true){
int selection = JOptionPane.showConfirmDialog(null, "Edit Job " +Registration +" ?", JobID, JOptionPane.OK_CANCEL_OPTION);
if (selection == JOptionPane.YES_OPTION) {
EditWorkDiaryGui(Integer.parseInt(JobID));
}
}
if(Customers.Delete==true){
int selection = JOptionPane.showConfirmDialog(null, "Delete Job " +Registration +" ?", JobID, JOptionPane.OK_CANCEL_OPTION);
if (selection == JOptionPane.YES_OPTION) {
DbHandlerWorkDiary.deleteWorkDiary(Integer.parseInt(JobID));
DbHandlerWorkDiary.WorkDiarySelect();
}
}
if(Customers.Delete==false && Customers.Edit==false){
UIManager.put("OptionPane.cancelButtonText", "View");
UIManager.put("OptionPane.okButtonText", "Add");
int selection = JOptionPane.showConfirmDialog(null, "Add or View Details for Job " +JobID +" ?", JobID, JOptionPane.OK_CANCEL_OPTION);
if (selection == JOptionPane.YES_OPTION) {
Invoices.AddInvoiceGui(Integer.parseInt(JobID));
}
if (selection == JOptionPane.CANCEL_OPTION) {
DbHandlerInvoices.InvoiceSelectJob(Integer.parseInt(JobID));
}
UIManager.put("OptionPane.cancelButtonText", "Cancel");
UIManager.put("OptionPane.okButtonText", "Ok");
}
}
});
}
}
This all works fine when run inside Eclipse. However, when I run the jar file, if the user enters the correct username and password, the button does not release and the diary page does not load. If I minimise the window, the diary page will then load. After this the app works fine.
I have tried debugging this in Eclipse, but it does not show any problems.
I have tried programmatically re sizing the window, but it also does not make the next page load.
I have checked all the files are present and all the dependencies exist as they should
Has anyone had any similar experiences, or any suggestions as to why this should be?
Java swing app not working properly when run as a runnable jar
Aucun commentaire:
Enregistrer un commentaire