Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.awt.event.*;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import sun.awt.image.PixelConverter.Bgrx;
- import javax.xml.parsers.*;
- import javax.xml.transform.*;
- import javax.xml.transform.dom.*;
- import javax.xml.transform.stream.*;
- import org.xml.sax.*;
- import org.w3c.dom.*;
- public class Layout1 {
- public static void main(String[] args) {
- //DECLARATION OF A FRAME
- JFrame f1 = new JFrame ("LOGIN PAGE");
- JLabel gender = new JLabel("Gender : ");
- gender.setBounds(100, 150, 70, 40);
- f1.add(gender);
- final JRadioButton rb1 = new JRadioButton("Male");
- final JRadioButton rb2 = new JRadioButton("Female");
- rb1.setBounds(150,150,70,40);
- rb2.setBounds(150,180,70,40);
- ButtonGroup bg=new ButtonGroup();
- bg.add(rb1);bg.add(rb2);
- //COMBO BOX COUNTRY
- String country [] = {"Select Country..","Iran","Afghanistan","America","Germany","Pakistan","Spain","France"};
- JLabel place = new JLabel("Country : ");
- place.setBounds(90, 220, 120, 20);
- f1.add(place);
- final JComboBox cb = new JComboBox(country);
- cb.setBounds(150,220,120,20);
- f1.add(cb);
- //COMBO BOX HEIGHT
- JLabel length = new JLabel("Height : ");
- length.setBounds(100, 250, 100, 20);
- f1.add(length);
- final JTextField height = new JTextField();
- height.setBounds(150, 250, 100, 20);
- f1.add(height);
- //COMBO BOX AGE
- JLabel old = new JLabel("Age : ");
- old.setBounds(100, 280, 100, 20);
- f1.add(old);
- final JTextField age = new JTextField();
- age.setBounds(150, 280, 100, 20);
- f1.add(age);
- //COMBO BOX NATIONALITY
- String nationality [] = {"Select Nationality","Irani","Afghani","American","German","Pakistani","Spanish","French"};
- JLabel nation = new JLabel("Nationality : ");
- nation.setBounds(80, 320, 100, 20);
- f1.add(nation);
- final JComboBox cb3 = new JComboBox(nationality);
- cb3.setBounds(150, 320, 100, 20);
- f1.add(cb3);
- //SAVE BUTTON WORK
- JButton save = new JButton ("Save ");
- save.setBackground(Color.CYAN);
- save.setBounds(150,350,100,30);
- //LOAD BUTTON WORK
- JButton load = new JButton ("Load ");
- load.setBackground(Color.CYAN);
- load.setBounds(150,400,100,30);
- //TEXTFIELD WORK
- JLabel name = new JLabel("Name : ");
- name.setBounds(100, 120, 200, 30);
- f1.add(name);
- final JTextField box = new JTextField();
- box.setBounds(150, 120, 200, 30);
- f1.add(box);
- //ACTION EVENTS WORK
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- FileWriter file = null;
- try {
- file = new FileWriter("C:\\Users\\Home\\Desktop\\Brother.txt");
- //NAME TEXTFIELD WORK
- try {
- box.getText();
- } catch (Exception e2) {
- System.out.println("There is an error in Name TextField");
- }
- final String data1 = box.getText();
- if(box.getText().isEmpty()){
- JOptionPane.showMessageDialog(null,
- "Error you did not enter a name, please try again.",
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- try {
- file.write(" Name : " + data1+"\n");
- } catch (IOException e3) {
- e3.printStackTrace();
- }
- //AGE TEXTFIELD WORK
- try {
- age.getText();
- }
- catch (Exception e2) {
- System.out.println("There is and error in Age TextField");
- }
- final String data4 = age.getText();
- if(age.getText().isEmpty()){
- JOptionPane.showMessageDialog(null,
- "Error you did not enter an age, please try again.",
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- /* Integer.parseInt(data4);
- int a = Integer.parseInt(data4);
- if ((a >= 18)&&(a <= 100)) {
- */
- try {
- file.write("Age : " + data4);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- //HEIGHT TEXTFIELD WORK
- try {
- height.getText();
- }
- catch (Exception e2) {
- System.out.println("There is an error in Height TextField");
- }
- final String data5 = height.getText();
- if(height.getText().isEmpty()){
- JOptionPane.showMessageDialog(null,
- "Error you did not enter a height, please try again.",
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- /*
- Double.parseDouble(data5);
- double b = Double.parseDouble(data5);
- if((b >= 3 )&&(b <= 10)){ */
- try {
- file.write("Height : " + data5);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- //try {
- //STORE COMBO BOX DATA OF COUNTRY NAME
- try{
- cb.getSelectedItem();
- }
- catch(Exception e2){
- System.out.println("Error in Country Name");
- }
- final String data2 = (String)cb.getSelectedItem();
- file.append(" Country : " + "\n" + data2+"\n");
- //STORE COMBO BOX DATA OF NATIONALITY
- try{
- cb.getSelectedItem();
- { final String data3 = (String)cb.getSelectedItem();
- file.write("Nationality : " + data3);
- }
- }
- catch(Exception e2){
- JOptionPane.showMessageDialog(null,
- "Error you did not enter a nationality, please try again.",
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- //STORE RADIO BUTTON DATA
- try{
- if(rb1.isSelected()==true)
- file.append(" Gender : " + "Male ");
- else if(rb2.isSelected()==true)
- file.append(" Gender : " + "Female ");
- else
- throw new Exception();
- }
- catch(Exception e2){
- JOptionPane.showMessageDialog(null, "Enter Gender", "try again", JOptionPane.ERROR_MESSAGE);
- }
- file.close();
- }
- catch (IOException e1) {
- System.err.println("Error occured in writing file");
- e1.printStackTrace();
- }
- }
- });
- f1.add(load);
- f1.add(rb1);
- f1.add(rb2);
- f1.add(save);
- f1.setLayout(null);
- f1.setVisible(true);
- f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f1.setSize(500,680);
- f1.setResizable(false);
- f1.setLocation(440, 10);
- }
- }
Add Comment
Please, Sign In to add comment