Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VINDOUZ APLIKACIJE
- ====================
- import javax.swing.*;
- public class Win1 extends JFrame{
- public Win1(){
- super("Nasa prva Win app");
- setSize(300, 100);
- }
- public static void main(String[] args) {
- Win1 w1;
- w1 = new Win1();
- w1.show();
- }
- }
- ====================
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Win2 extends JFrame{
- JButton btRadi;
- class RadiListener implements ActionListener{
- public void actionPerformed(ActionEvent e){
- e.getSource();
- System.out.println("STOP IT!");
- }
- }
- public Win2(){
- super("App with one pointless button.");
- setSize(400, 100);
- Container cp = this.getContentPane();
- cp.setLayout(new FlowLayout());
- btRadi = new JButton("Radi");
- btRadi.addActionListener(new RadiListener());
- cp.add(btRadi);
- //Drugi nacin cp.add(btRadi = new JButton("Radi"));
- }
- public static void main(String args[]){
- Win2 w2 = new Win2();
- w2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w2.show();
- }
- }
- ===================
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Win3 extends JFrame implements ActionListener{
- JButton btRadi1, btRadi2, btRadi3;
- public Win3(){
- super("Win3");
- setSize(420, 200);
- Container cp = this.getContentPane();
- cp.setLayout(new FlowLayout());
- cp.add(btRadi1 = new JButton("Radi 1"));
- btRadi1.addActionListener(this);
- cp.add(btRadi2 = new JButton("Radi 2"));
- btRadi2.addActionListener(this);
- cp.add(btRadi3 = new JButton("Radi 3"));
- btRadi3.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e){
- System.out.println("Pritisnuto je dumge "+e.getActionCommand());
- }
- public static void main(String[] args) {
- Win3 w3 = new Win3();
- w3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w3.show();
- }
- }
- =================
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Win4 extends JFrame implements ActionListener{
- private JLabel lb1, lb2, lbRez;
- private JTextField tf1, tf2, tfRez;
- private JButton btSaberi, btOduzmi;
- public Win4(){
- super("Sabirac/Oduzimac");
- setSize(200, 420);
- Container cp = this.getContentPane();
- //cp.setLayout(new FlowLayout());
- cp.setLayout(new GridLayout(4,2));
- cp.add(lb1 = new JLabel("Broj 1: "));
- cp.add(tf1 = new JTextField(15));
- cp.add(lb2 = new JLabel("Broj 2: "));
- cp.add(tf2 = new JTextField(15));
- cp.add(lbRez = new JLabel("Rezultat: "));
- cp.add(tfRez = new JTextField(15));
- tfRez.setEditable(false);
- cp.add(btSaberi = new JButton("Saberi"));
- btSaberi.addActionListener(this);
- cp.add(btOduzmi = new JButton("Oduzmi"));
- btOduzmi.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e){
- double broj1, broj2, rez;
- String str;
- try{
- str = tf1.getText();
- broj1 = Double.parseDouble(str);
- str = tf2.getText();
- broj2 = Double.parseDouble(str);
- //if (e.getActionCommand().equals("Saberi"))
- // rez = broj1 + broj2;
- //else
- // rez = broj1 - broj2;
- if (e.getSource() == btSaberi)
- rez = broj1 + broj2;
- else
- rez = broj1 - broj2;
- tfRez.setText(Double.toString(rez));
- }catch (Exception ee){
- tfRez.setText("Nepravilno zadat neki broj!");
- }
- }
- public static void main(String[] args) {
- Win4 w4 = new Win4();
- w4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w4.show();
- }
- }
- ===================
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Win5 extends JFrame{
- JComboBox cb;
- public Win5(){
- super("Qwerty");
- String imena[]= {"Marko", "Pera", "Laza", "Zika", "Mika"};
- setSize(120, 100);
- Container cp = this.getContentPane();
- cp.setLayout(new FlowLayout());
- cb = new JComboBox();
- for (int k = 0; k < imena.length; k++)
- cb.addItem(imena[k]);
- cp.add(cb);
- }
- public static void main(String[] args) {
- Win5 w5 = new Win5();
- w5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w5.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement