• Post Reply Bookmark Topic Watch Topic
  • New Topic

Textfields and Button in the pop up window  RSS feed

 
Shiva Gajjala
Ranch Hand
Posts: 77
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends , I am doing my college assigment .I am struck up in populating a pop up window that contains multiple text boxes when radiobutton is clicked.Please suggest relevant method and some code .My task is below .
Homework #2
1. Create a GUI that has two JRadioButtions which allow a user to select between an employee and a manager. (20 points)
2. Create a GUI that pops up if an employee is selected. This new window should contain JLabels with JTextFields that allow the user to enter in all the employee's relevant information - e.g. Name, Title, Age, and Salary. Use the same inputs from the Jane Doe case in Homework #1. The new window should also allow the user to raise the employee's salary by a certain percentage - JTextField (% Increase). Use the employee raiseSalary(int percent) method from Homework #1. Lastly, the new window should include a calculate button which computes and outputs the new salary when pressed. In this case, the new salary would be 82500.0. (20 points)
3. Create a GUI that pops up if a manager is selected. This new window should contain JLabels with JTextFields that allow the user to enter in all the manager's relevant information - e.g. Name, Title, Age, Years of Experience, Highest Degree Earned, Salary, and Promotion Bonus. Use the same inputs from the John Doe case in Homework #1. The new window should also allow the user to raise the manager's salary by a certain percentage - JTextField (% Increase). Use the manager raiseSalary(int percent) method from Homework #1. Lastly, the new window should include a calculate button which computes and outputs the new salary when pressed. In this case, the new salary would be 115000.0. (20 points)
4. Create a GUI error message that pops up if the user enters invalid information into the GUI from question #2. (20 points)
5. Create a GUI error message that pops up if the user enters invalid information into the GUI from question #3. (20 points)

My code is below,
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My task is below


Yes, well we are not here to do your homework. If you actually ask a specific question we might be able to help or point you in the right direction.

In the meantime some pointers:

1. Don't use Button, that is an AWT component. Use JButton for Swing
2. Don't use a null layout. Swing was designed to be used with layout managers.
3. Don't use setSize(). Instead use pack(), BEFORE you make the frame visible.

I suggest you start by reading the Swing tutorial. There are section on:

1. Using layout managers
2. How to Use Radio Buttons
3. How to Make Dialogs

Each section has demo code that you can download and execute to learn a concept. I suggest you start with the working code and make your changes. Each demo will show you a better way to structure your code.
 
Shiva Gajjala
Ranch Hand
Posts: 77
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob Camick, I would like to do my homework on my own . I posted it just to make my question clear. I will make changes as per your suggestions and learn from the link provided. Can you tell me what method should I use to display a new frame as popup so that I can display labels,text fields and a button as per my assignment. When I use JOptionPane.showInputDialog() method I could get only one label and a textbox with a button, but I want multiple labels and text boxes in the pop up window.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: JOptionPane#showMessageDialog(...) and showConfirmDialog(...) take any Object (can be a JPanel) as the message parameter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!