so I have been writing a program that takes user input for employee data and adds it to an ArrayList
for display. The program is working fine except for two points. The first is that I am trying to validate that the user entered an hourly rate between $6 and $160. Here is the code for that:
try{
double r = Double.parseDouble(rate.getText());
if (r >= 6 && r <= 150){
test.setRate(r);
}
} catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Sorry, hourly rate must be between $6 and $150.");
return;
}
It does validate that it is between those values, but if it is not it simply sets it to 0 rather than display the message to the user and return out of the method.
My second problem is a little more complex, and to be honest I am completely lost. When I run the program to test or to debug it opens two windows. The primary window is completely blank but controls the EXIT_ON_CLOSE
command while the second has everything that I coded into it. I have tried searching for a second JFrame
that might have been initialized but cannot find one. I have a larger amount of code and am not sure what might be needed but here is the code that I believe is causing the problem based off of the behavior:
face = new JFrame();
face.setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GroupLayout design = new GroupLayout(face.getContentPane());
face.setLayout(design);
face.setVisible(true);
design.setAutoCreateGaps(true);
design.setAutoCreateContainerGaps(true);
design.setVerticalGroup
(
design.createSequentialGroup()
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(fName)
.addComponent(first)
.addComponent(list))
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(lName)
.addComponent(last))
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(hWork)
.addComponent(hours))
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(hRate)
.addComponent(rate))
.addComponent(admin)
.addComponent(market)
.addComponent(account)
.addComponent(prod)
.addComponent(sales)
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(submit)
.addComponent(exit))
);
design.setHorizontalGroup
(
design.createSequentialGroup()
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(fName)
.addComponent(lName)
.addComponent(hWork)
.addComponent(hRate)
.addComponent(admin)
.addComponent(market)
.addComponent(account)
.addComponent(prod)
.addComponent(sales)
.addComponent(submit))
.addGroup(design.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(first)
.addComponent(last)
.addComponent(hours)
.addComponent(rate)
.addComponent(exit))
.addComponent(list)
);
}
Other than creating the individual controls this is everything that has to do with the GUI design. Any insight would be very welcome here! If I forgot to post something I would be happy to do so.