diff --git a/Lab03/.classpath b/Lab03/.classpath new file mode 100644 index 0000000..9af0373 --- /dev/null +++ b/Lab03/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Lab03/.project b/Lab03/.project new file mode 100644 index 0000000..f597ba4 --- /dev/null +++ b/Lab03/.project @@ -0,0 +1,17 @@ + + + Lab03 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Lab03/src/lab03/Form.java b/Lab03/src/lab03/Form.java new file mode 100644 index 0000000..54ab0a1 --- /dev/null +++ b/Lab03/src/lab03/Form.java @@ -0,0 +1,95 @@ +package lab03; + +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +public class Form { + + static JFrame frame; + static JPanel root; + static JTextField fName; + static JRadioButton fGenderMale; + static JRadioButton fGenderFemale; + static JCheckBox fMarried; + static JTextArea fAddress; + static JButton bSubmit; + + public Form() { + frame = new JFrame("Lab03"); + root = new JPanel(); + root.setLayout(new BoxLayout(root, BoxLayout.Y_AXIS)); + + this.buildForm(); + + frame.add(root); + frame.setSize(500, 300); + frame.setVisible(true); + } + + private void buildForm() { + JPanel pName = new JPanel(new FlowLayout(FlowLayout.LEADING)); + pName.add(new JLabel("Name:")); + fName = new JTextField(20); + pName.add(fName); + root.add(pName); + + JPanel pGender = new JPanel(new FlowLayout(FlowLayout.LEADING)); + pGender.add(new JLabel("Gender:")); + fGenderMale = new JRadioButton("Male"); + fGenderFemale = new JRadioButton("Female"); + ButtonGroup groupGender = new ButtonGroup(); + groupGender.add(fGenderMale); + groupGender.add(fGenderFemale); + pGender.add(fGenderMale); + pGender.add(fGenderFemale); + root.add(pGender); + + JPanel pMarried = new JPanel(new FlowLayout(FlowLayout.LEADING)); + pMarried.add(new JLabel("Married:")); + fMarried = new JCheckBox(); + pMarried.add(fMarried); + root.add(pMarried); + + JPanel pAddress = new JPanel(new FlowLayout(FlowLayout.LEADING)); + pAddress.add(new JLabel("Address:")); + fAddress = new JTextArea(5, 30); + pAddress.add(fAddress); + root.add(pAddress); + + bSubmit = new JButton("Submit"); + Form that = this; + bSubmit.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + that.buildResult(); + } + }); + root.add(bSubmit); + + root.updateUI(); + } + + private void buildResult() { + root.removeAll(); + + root.add(new JLabel("Name: " + fName.getText())); + root.add(new JLabel("Gender: " + (fGenderMale.isSelected() ? "Male" : "Female"))); + root.add(new JLabel("Married: " + (fMarried.isSelected() ? "Yes" : "No"))); + root.add(new JLabel("Address: " + fAddress.getText())); + + root.updateUI(); + } + +} diff --git a/Lab03/src/lab03/Lab02.java b/Lab03/src/lab03/Lab02.java new file mode 100644 index 0000000..baf0d83 --- /dev/null +++ b/Lab03/src/lab03/Lab02.java @@ -0,0 +1,9 @@ +package lab03; + +public class Lab02 { + + public static void main(String[] args) { + new Form(); + } + +}