chore: Lab03
This commit is contained in:
parent
d823679db2
commit
70f0cdf757
10
Lab03/.classpath
Normal file
10
Lab03/.classpath
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
Lab03/.project
Normal file
17
Lab03/.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Lab03</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
95
Lab03/src/lab03/Form.java
Normal file
95
Lab03/src/lab03/Form.java
Normal file
@ -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();
|
||||
}
|
||||
|
||||
}
|
9
Lab03/src/lab03/Lab02.java
Normal file
9
Lab03/src/lab03/Lab02.java
Normal file
@ -0,0 +1,9 @@
|
||||
package lab03;
|
||||
|
||||
public class Lab02 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Form();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user