Hi i need help with this program im doing for class. the question is: Write a co
ID: 3536488 • Letter: H
Question
Hi i need help with this program im doing for class. the question is:
Write a complete Java application that will allow you to practice with GUI components. Create a screen that will display the following:
4 text fields to allow the entry of:
- first name
- last name
- amount (numeric format for example 999.99; maximum number allowed 999.99)
- memo field,
3 combo boxes (drop-down lists) to allow the entry of a date;
- the first one to select a month (January %u2013 December);
- the second to select the day (1-31)
- the third one to select the year (2005-2015).
a group of 3 radio buttons with the following descriptions:
- Single (default),
- Married,
- Divorced.
2 checkboxes with the description:
- Veteran.
- Full Time Student.
Include a button that named %u2018Report%u2019. When you click Report you should display a password protected screen; if the password is correct then it creates a report (it adds all the above information to a textArea that contains headings.) If the person is Single display the letter S, if (s)he is Married display the letter M and if (s)he is divorced display the letter D.If the person is Veteran store the letter V, otherwise N. If the person is Full time student store the letter F, otherwise P.
Include a button named %u2018Add person%u2019 that will clear the fields and will allow you to enter the info for another person.
here is my coding:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GUIComponents extends JFrame
{
private JLabel firstLabel, lastLabel, amountLabel, memoLabel, passLabel;
private JTextField firstTF, lastTF, amountTF, memoTF;
private JComboBox monthCoB,dayCoB,yearCoB;
private String [] months = {"Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept","Oct", "Nov", "Dec" };
private String [] days = {"Day","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31",};
private String [] years = {"Year","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015"};
private JRadioButton singleRB,marriedRB,divorcedRB;
private ButtonGroup radioButtonGroup;
private JCheckBox veteranChB,fullTimeChB;
private JPasswordField passPF;
private JButton reportButton,addButton;
private JPanel p1,p2,p3,p4,p5;
public GUIComponents()
{
setLayout ( new GridLayout(2,3) );
p1 = new JPanel();
add(p1);
p2 = new JPanel();
add(p2);
p3 = new JPanel();
add(p3);
p4 = new JPanel();
add(p4);
firstLabel = new JLabel("First Name");
firstTF = new JTextField(10);
lastLabel = new JLabel("Last Name");
lastTF = new JTextField(10);
amountLabel = new JLabel("Amount");
amountTF = new JTextField(10);
memoLabel = new JLabel("Memo");
memoTF = new JTextField(10);
reportButton = new JButton("Report");
addButton =new JButton("Add Person");
passLabel = new JLabel("Enter the password to view the report");
passPF = new JPasswordField(10);
//_____________________________________________________
//ComboBox
monthCoB= new JComboBox(months);
dayCoB= new JComboBox(days);
yearCoB= new JComboBox(years);
//_____________________________________________________
//radio button & group
singleRB = new JRadioButton("Single",true);
marriedRB = new JRadioButton("Married");
divorcedRB = new JRadioButton("Divorced");
radioButtonGroup = new ButtonGroup();
radioButtonGroup.add(singleRB);
radioButtonGroup.add(marriedRB);
radioButtonGroup.add(divorcedRB);
//____________________________________________________
//Checkbox
veteranChB = new JCheckBox("Veteran");
fullTimeChB = new JCheckBox("Full-Time Student");
//____________________________________________________
p1.add(firstLabel);
p1.add(firstTF);
p1.add(lastLabel);
p1.add(lastTF);
p1.add(amountLabel);
p1.add(amountTF);
p1.add(memoLabel);
p1.add(memoTF);
p1.add(reportButton);
reportButton.addActionListener(new passPFActionListener());
p1.add(addButton);
addButton.addActionListener(new clearFieldsActionListener());
p2.add(monthCoB);
p2.add(dayCoB);
p2.add(yearCoB);
p3.add(singleRB);
p3.add(marriedRB);
p3.add(divorcedRB);
p4.add(veteranChB);
p4.add(fullTimeChB);
}
private class passPFActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
p4.add(passLabel);
p4.add(passPF);
if (passPF.getText() == "BMCC");
JOptionPane.showMessageDialog(null, "Hello");
}
}
private class clearFieldsActionListener implements ActionListener// clear
{
public void actionPerformed(ActionEvent a)
{
firstTF.setText(" ");
lastTF.setText(" ");
amountTF.setText(" ");
memoTF.setText(" ");
}
}
}
Please help with the password field and the actionlisteners, i would really appreciate it.
Explanation / Answer
import java.awt.Frame; // Using Frame class in package java.awt // A GUI program is written as a subclass of Frame - the top-level container // This subclass inherits all properties from Frame, e.g., title, icon, buttons, content-pane public class MyGUIProgram extends Frame { // Constructor to setup the GUI components public MyGUIProgram() { ...... } ...... ...... // The entry main() method public static void main(String[] args) { // Invoke the constructor (to setup the GUI) by allocating an instance MyGUIProgram m = new MyGUIProgram(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.