jeudi 25 janvier 2018

How to load Text from TextField, checkbox, RadioButton, ComboBox to one Big Text Field

I'm beginner on Java and I'm writing a simple program for recruiting employees. I have few Questions with JtextField, few checkbox with text, RadioButton with text and Combobox. I need the data entered in the text windows, checkbox, drop-down list to be thrown into the large window on the right. At the moment there are only data from the text windows, but not from the top just in the middle of the field. Please help.

package appka;

import javax.swing.*;

import java.awt.Checkbox; import java.awt.event.*;

public class CzwartaApp {

public static void main(String[] args) {
    // Klasy obiektow
    JFrame frame = new JFrame("Czwarta Aplikacja");

    JButton btnSubmit = new JButton("Wypisz");
    JButton btnExit = new JButton("Wyjdz");

    JLabel lbl1 = new JLabel("imię");
    JLabel lbl2 = new JLabel("nazwisko");
    JLabel lbl3 = new JLabel("stanowisko");
    JLabel lbl4 = new JLabel("E-mail");
    JLabel lbl5 = new JLabel("");
    JLabel lbl6 = new JLabel("Jakie znasz języki programowania?");
    JLabel lbl7 = new JLabel("Wybierz poziom języka angielskiego?");
    JLabel lbl8 = new JLabel("Wybierz kurs programowania?");
    JLabel lbl9 = new JLabel("Dane Kontaktowe");

    JTextField tf1 = new JTextField();
    JTextField tf2 = new JTextField();
    JTextField tf3 = new JTextField();
    JTextField tf4 = new JTextField();
    JTextField tf5 = new JTextField();

    Checkbox checkbox1 = new Checkbox("Java");
    Checkbox checkbox2 = new Checkbox("Python");
    Checkbox checkbox3 = new Checkbox("Inne");

    JRadioButton btn1 = new JRadioButton();
    btn1.setText("podstawowy");
    JRadioButton btn2 = new JRadioButton();
    btn2.setText("średnio-zaawansowany");
    JRadioButton btn3 = new JRadioButton();
    btn3.setText("zaawansowany");
    ButtonGroup group = new ButtonGroup ();
    group.add(btn1); group.add(btn2); group.add(btn3);

    JComboBox kurs = new JComboBox();
    kurs.addItem("FrontEnd Developer");
    kurs.addItem("BackEnd Developer");

    // Pozycjonowanie
    lbl1.setBounds(20, 20, 100, 20);
    tf1.setBounds(20, 70, 100, 20);
    lbl2.setBounds(20, 120, 100, 20);
    tf2.setBounds(20, 170, 100, 20);
    lbl3.setBounds(20, 220, 100, 20);
    tf3.setBounds(20, 270, 100, 20);
    lbl4.setBounds(20, 320, 100, 20);
    tf4.setBounds(20, 370, 100, 20);
    tf5.setBounds(500, 20, 250, 300);
    lbl5.setBounds(20, 420, 300, 20);
    lbl6.setBounds(200, 20, 250, 20);
    lbl7.setBounds(200, 220, 250, 20);
    lbl8.setBounds(200, 350, 250, 20);
    lbl9.setBounds(500, 50, 200, 20);
    btnSubmit.setBounds(20, 470, 100, 20);
    btnExit.setBounds(220, 470, 100, 20);
    checkbox1.setBounds(200, 70, 250, 20);
    checkbox2.setBounds(200, 120, 250, 20);
    checkbox3.setBounds(200, 170, 250, 20);
    btn1.setBounds(200, 250, 250, 20);
    btn2.setBounds(200, 280, 250, 20);
    btn3.setBounds(200, 310, 250, 20);
    kurs.setBounds(200, 380, 250, 20);


    // Obsluga zdarzen
    btnSubmit.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){

            String imie = tf1.getText();
            String nazwisko = tf2.getText();
            String stanowisko = tf3.getText();
            String email = tf4.getText();

            tf5.setText(imie+" "+nazwisko+" "+stanowisko+" "+email);

        }

    });
    btnExit.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            System.exit(0);
        }
    });
    // Dodanie do okna
    frame.add(btnSubmit); frame.add(btnExit);
    frame.add(tf1); frame.add(tf2); frame.add(tf3);frame.add(tf4);frame.add(tf5);
    frame.add(lbl1); frame.add(lbl2); frame.add(lbl3); frame.add(lbl4);frame.add(lbl5);
    frame.add(lbl6);frame.add(lbl7);frame.add(lbl8);frame.add(lbl9);
    frame.add(checkbox1); frame.add(checkbox2); frame.add(checkbox3);
    frame.add(btn1); frame.add(btn2); frame.add(btn3);
    frame.getContentPane().add(kurs);
    frame.setSize(800, 600);
    frame.setLayout(null);
    frame.setVisible(true);
}

}




Aucun commentaire:

Enregistrer un commentaire