You are on page 1of 7

JAVASwingFormPrimer.

java

package swing_1;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class JAVASwingFormPrimer {

private JFrame frmJavaSwingForm;


private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;

/** * Launch the application. */

public static void main(String[] args) {


EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JAVASwingFormPrimer window = new JAVASwingFormPrimer();
window.frmJavaSwingForm.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/** * Create the application. */

public JAVASwingFormPrimer() {
initialize();
}
/** * Initialize the contents of the frame. */
private void initialize() {
frmJavaSwingForm = new JFrame();
frmJavaSwingForm.setTitle("JAVA Swing Form Primer");
frmJavaSwingForm.setBounds(100, 100, 450, 463);
frmJavaSwingForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmJavaSwingForm.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("Ime:");
lblNewLabel.setBounds(24, 27, 46, 14);
frmJavaSwingForm.getContentPane().add(lblNewLabel);

textField = new JTextField();


textField.setBounds(101, 24, 143, 20);
frmJavaSwingForm.getContentPane().add(textField);
textField.setColumns(10);

JLabel lblNewLabel_1 = new JLabel("Telefon:");


lblNewLabel_1.setBounds(24, 66, 46, 14);
frmJavaSwingForm.getContentPane().add(lblNewLabel_1);

textField_1 = new JTextField();


textField_1.setBounds(101, 63, 143, 20);
frmJavaSwingForm.getContentPane().add(textField_1);
textField_1.setColumns(10);

JLabel lblNewLabel_2 = new JLabel("email:");


lblNewLabel_2.setBounds(24, 104, 46, 14);
frmJavaSwingForm.getContentPane().add(lblNewLabel_2);

textField_2 = new JTextField();


textField_2.setBounds(101, 101, 143, 20);
frmJavaSwingForm.getContentPane().add(textField_2);
textField_2.setColumns(10);

JLabel lblNewLabel_3 = new JLabel("Adresa:");


lblNewLabel_3.setBounds(24, 144, 59, 14);
frmJavaSwingForm.getContentPane().add(lblNewLabel_3);

JTextArea textArea = new JTextArea();


textArea.setBounds(101, 132, 143, 55);
frmJavaSwingForm.getContentPane().add(textArea);

JLabel lblNewLabel_4 = new JLabel("Pol:");


lblNewLabel_4.setBounds(24, 211, 46, 14);
frmJavaSwingForm.getContentPane().add(lblNewLabel_4);

JRadioButton RadioButton = new JRadioButton("Musko");


RadioButton.setBounds(93, 207, 109, 23);
frmJavaSwingForm.getContentPane().add(RadioButton);
JRadioButton RadioButton_1 = new JRadioButton("Zensko");
RadioButton_1.setBounds(217, 207, 109, 23);
frmJavaSwingForm.getContentPane().add(RadioButton_1);

ButtonGroup btnGrp = new ButtonGroup();


btnGrp.add(RadioButton);
btnGrp.add(RadioButton_1);

JLabel lblNewLabel_5 = new JLabel("Zanimanje: ");


lblNewLabel_5.setBounds(24, 279, 78, 14);
frmJavaSwingForm.getContentPane().add(lblNewLabel_5);

JComboBox comboBox = new JComboBox();


comboBox.addItem("Select");
comboBox.addItem("Pravnik");
comboBox.addItem("Inzenjer");
comboBox.addItem("Student");
comboBox.addItem("Ostalo");
comboBox.setBounds(153, 275, 91, 22);
frmJavaSwingForm.getContentPane().add(comboBox);

JButton btnSubmit = new JButton("OK");


btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(textField.getText().isEmpty()||
(textField_1.getText().isEmpty())||
(textField_2.getText().isEmpty())||
(textArea.getText().isEmpty())||
((RadioButton_1.isSelected())&&(RadioButton.isSelected()))||
(comboBox.getSelectedItem().equals("Select")))
JOptionPane.showMessageDialog(null, "GREŠKA - Morate popuniti sve podatke");
else
JOptionPane.showMessageDialog(null, "Podaci su u redu i biće prosleđeni!");

}
});
btnSubmit.setBounds(26, 371, 89, 23);
frmJavaSwingForm.getContentPane().add(btnSubmit);

JButton btnClear = new JButton("Obrisi");


btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_1.setText(null);
textField_2.setText(null);
textField.setText(null);
textArea.setText(null);
RadioButton.setSelected(false);
RadioButton_1.setSelected(false);
comboBox.setSelectedItem("Select");

}
});
btnClear.setBounds(193, 371, 89, 23);
frmJavaSwingForm.getContentPane().add(btnClear);
}
}
IZVORNI
JAVASwingFormPrimer.java

package swing_1;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
import javax.swing.JScrollBar;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import java.awt.Font;

public class JAVASwingFormPrimer {

private JFrame frmJavaSwingForma;


private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JAVASwingFormPrimer window = new JAVASwingFormPrimer();
window.frmJavaSwingForma.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public JAVASwingFormPrimer() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmJavaSwingForma = new JFrame();
frmJavaSwingForma.setTitle("Java swing forma - primer");
frmJavaSwingForma.setBounds(100, 100, 484, 486);
frmJavaSwingForma.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmJavaSwingForma.getContentPane().setLayout(null);

textField = new JTextField();


textField.setBounds(128, 28, 86, 20);
frmJavaSwingForma.getContentPane().add(textField);
textField.setColumns(10);

JLabel lblName = new JLabel("Ime:");


lblName.setBounds(65, 31, 46, 14);
frmJavaSwingForma.getContentPane().add(lblName);

JLabel lblPhone = new JLabel("Telefon #");


lblPhone.setBounds(65, 68, 59, 14);
frmJavaSwingForma.getContentPane().add(lblPhone);

textField_1 = new JTextField();


textField_1.setBounds(128, 65, 86, 20);
frmJavaSwingForma.getContentPane().add(textField_1);
textField_1.setColumns(10);

JLabel lblEmailId = new JLabel("Email:");


lblEmailId.setBounds(65, 115, 46, 14);
frmJavaSwingForma.getContentPane().add(lblEmailId);

textField_2 = new JTextField();


textField_2.setBounds(128, 112, 247, 17);
frmJavaSwingForma.getContentPane().add(textField_2);
textField_2.setColumns(10);

JLabel lblAddress = new JLabel("Adresa:");


lblAddress.setBounds(65, 162, 46, 14);
frmJavaSwingForma.getContentPane().add(lblAddress);

JTextArea textArea_1 = new JTextArea();


textArea_1.setBounds(126, 157, 212, 40);
frmJavaSwingForma.getContentPane().add(textArea_1);

JButton btnClear = new JButton("Obri\u0161i");


btnClear.setFont(new Font("Tahoma", Font.BOLD, 11));

btnClear.setBounds(312, 387, 89, 23);


frmJavaSwingForma.getContentPane().add(btnClear);
JLabel lblSex = new JLabel("Pol:");
lblSex.setBounds(65, 228, 46, 14);
frmJavaSwingForma.getContentPane().add(lblSex);

JLabel lblMale = new JLabel("Mu\u0161ki");


lblMale.setBounds(128, 228, 46, 14);
frmJavaSwingForma.getContentPane().add(lblMale);

JLabel lblFemale = new JLabel("\u017Denski");


lblFemale.setBounds(301, 228, 46, 14);
frmJavaSwingForma.getContentPane().add(lblFemale);

JRadioButton radioButton = new JRadioButton("");


radioButton.setBounds(353, 224, 109, 23);
frmJavaSwingForma.getContentPane().add(radioButton);

JRadioButton radioButton_1 = new JRadioButton("");


radioButton_1.setBounds(162, 224, 109, 23);
frmJavaSwingForma.getContentPane().add(radioButton_1);

// ButtonGroup = new brnGrp ButtonGroup();

JLabel lblOccupation = new JLabel("Izaberite zanimanje:");


lblOccupation.setBounds(65, 288, 105, 14);
frmJavaSwingForma.getContentPane().add(lblOccupation);

JComboBox<String> comboBox = new JComboBox<String>();


comboBox.addItem("Select");
comboBox.addItem("Ekonomista");
comboBox.addItem("Inzenjer");
comboBox.addItem("Doktor");
comboBox.addItem("Student");
comboBox.addItem("Ostalo");
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
comboBox.setBounds(180, 285, 91, 20);
frmJavaSwingForma.getContentPane().add(comboBox);

JButton btnSubmit = new JButton("OK");


btnSubmit.setFont(new Font("Tahoma", Font.BOLD, 11));

btnSubmit.setBackground(Color.WHITE);
btnSubmit.setForeground(Color.BLACK);
btnSubmit.setBounds(65, 387, 89, 23);
frmJavaSwingForma.getContentPane().add(btnSubmit);

btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(textField.getText().isEmpty()||
(textField_1.getText().isEmpty())||(textField_2.getText().isEmpty())||
(textArea_1.getText().isEmpty())||
((radioButton_1.isSelected())&&(radioButton.isSelected()))||
(comboBox.getSelectedItem().equals("Select")))
JOptionPane.showMessageDialog(null, "GREŠKA - Morate
popuniti sve podatke");
else
JOptionPane.showMessageDialog(null, "Podaci su u redu i biće
prosleđeni!");
}
});

btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_1.setText(null);
textField_2.setText(null);
textField.setText(null);
textArea_1.setText(null);
radioButton.setSelected(false);
radioButton_1.setSelected(false);
comboBox.setSelectedItem("Select");

}
});

}
}

You might also like