Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class Win1 extends JFrame{
- public Win1(){
- super("Nasa prva Win aplikacija"); // naslov prozora(aplikacije)
- setSize(300, 100);
- }
- public static void main(String[] args) {
- Win1 w1;
- w1 = new Win1();
- //w1.show(); ili ovo ili ovo ispod za prikazivanje
- w1.show(true);
- }
- }
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Win2 extends JFrame{
- JButton btRadi; //pravimo dugme
- class RadiListener implements ActionListener{
- public void actionPerformed(ActionEvent e){
- System.out.println("Pritisnuto je dugme");
- }
- }
- public Win2(){
- super("Aplikacija sa jednim dugmetom"); // naslov prozora(aplikacije)
- setSize(400, 100); // velicina prozora
- Container cp = this.getContentPane(); // pravlejnje kontejnera
- cp.setLayout(new FlowLayout()); // FlowLayout dodaje sve od gsve jedne do druge i onda ih centrira uz gornju ivicu
- btRadi = new JButton("Radi"); // pravimo samo dugme na kojem pise Radi
- btRadi.addActionListener(new RadiListener()); // pozivamo da radi RadiListener
- cp.add(btRadi); // dodajemo to dugme na layout u prozor
- //cp.add(btRadi = new JButton("Radi")); // moze i ovako da se napravi dugme koje odma prosledjujemo u cp
- }
- public static void main(String[] args) {
- Win2 w2 = new Win2();
- w2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // ovo pravi da kad se klikne na x da se tad i zatvori aplikacija da prestane da radi
- 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(400, 200);
- Container cp = this.getContentPane();
- cp.setLayout(new FlowLayout());
- cp.add(btRadi1 = new JButton("Radi1"));
- btRadi1.addActionListener(this);
- cp.add(btRadi2 = new JButton("Radi2"));
- btRadi2.addActionListener(this);
- cp.add(btRadi3 = new JButton("Radi3"));
- btRadi3.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e){
- System.out.println("Pritusnuto je dugme "+e.getActionCommand());
- System.out.println("Pritusnuto je dugme "+e.getSource()); // prikazuje nformacije o dugmetu
- }
- 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("Wabirac/Oduzimac");
- setSize(250, 180);
- 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); // zabranjuje upis u to polje
- 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("Nepravilan unos");
- }
- }
- public static void main(String[] args) {
- Win4 w4 = new Win4();
- w4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w4.show();
- }
- }
- //dodati za mnozenje i dijeljenje na ovu aplikaciju, kod dijeljenja ne smije se dijeliti sa 0 pa exception
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Win5 extends JFrame {
- JComboBox cb;
- String imena[] = {"Miko", "Pero", "Lazo", "Ziko", "Mika"};
- public Win5(){
- super("Win 5");
- setSize(200, 100);
- Container cp = this.getContentPane();
- cp.setLayout(new FlowLayout());
- cb = new JComboBox();
- for(int k = 0; k < imena.length; k++)
- cb.addItem(imena[k]);
- cb.setSelectedIndex(3); // koji ce bit prvi selektovan
- cp.add(cb);
- }
- public static void main(String[] args) {
- Win5 w5 = new Win5();
- w5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w5.show();
- }
- }
- public class Ucenik {
- private String prezime, ime;
- private int razred;
- private char odeljenje;
- private int ocene[];
- public Ucenik(String prezime, String ime, int razred,
- char odeljenje, int oc[]){
- this.prezime = prezime;
- this.ime = ime;
- this.razred = razred;
- this.odeljenje = odeljenje;
- ocene = new int[5];
- for (int k = 0; k<5; k++){
- ocene[k] = oc[k];
- }
- }
- public String getPrezime() {
- return prezime;
- }
- public void setPrezime(String prezime) {
- this.prezime = prezime;
- }
- public String getIme() {
- return ime;
- }
- public void setIme(String ime) {
- this.ime = ime;
- }
- public int getRazred() {
- return razred;
- }
- public void setRazred(int razred) {
- this.razred = razred;
- }
- public char getOdeljenje() {
- return odeljenje;
- }
- public void setOdeljenje(char odeljenje) {
- this.odeljenje = odeljenje;
- }
- public int getOcena(int k){
- if ((k < 0) || (k >=5)) return 0;
- return ocene[k];
- }
- public void setOcene(int k, int oc){
- if((k >= 0) && (k < 5))
- ocene[k] = oc;
- }
- }
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import java.io.*;
- public class WinUcenici extends JFrame implements ActionListener{
- private JLabel lbPrezime, lbIme, lbRazred, lbOdeljenje, lbOcene[];
- private JTextField tfPrezime, tfIme, tfRazred, tfOdeljenje, tfOcene[];
- private JLabel lbIzbor;
- private JComboBox cbIzbor;
- private Vector<Ucenik> vecu;
- public WinUcenici(){
- super("Ucenici");
- setSize(200,400);
- Container cp = this.getContentPane();
- cp.setLayout(new GridLayout(10, 2));
- cp.add(lbIzbor = new JLabel("Biraj"));
- cp.add(cbIzbor = new JComboBox());
- cbIzbor.addActionListener(this);
- cp.add(lbPrezime = new JLabel("Prezime"));
- cp.add(tfPrezime = new JTextField(15));
- tfPrezime.setEditable(false);
- cp.add(lbIme = new JLabel("Ime"));
- cp.add(tfIme = new JTextField(15));
- tfIme.setEditable(false);
- cp.add(lbRazred = new JLabel("Razred"));
- cp.add(tfRazred = new JTextField(15));
- tfRazred.setEditable(false);
- cp.add(lbOdeljenje = new JLabel("Odeljenje"));
- cp.add(tfOdeljenje = new JTextField(15));
- tfOdeljenje.setEditable(false);
- lbOcene = new JLabel[5];
- tfOcene = new JTextField[5];
- for (int k = 0 ; k < 5; k++){
- cp.add(lbOcene[k] = new JLabel("Ocena "+(k+1)));
- cp.add(tfOcene[k] = new JTextField(15));
- tfOcene[k].setEditable(false);
- }
- vecu = new Vector<Ucenik>();
- try{
- FileReader fr = new FileReader("Ucenici.txt");
- Scanner sc = new Scanner(fr);
- while (sc.hasNext()){
- String pr, ime;
- int razr;
- char od;
- int oc[]= new int[5];
- pr = sc.next();
- ime = sc.next();
- razr = sc.nextInt();
- od = sc.next().charAt(0);
- for(int k = 0; k < 5; k++)
- oc[k]= sc.nextInt();
- vecu.add(new Ucenik(pr, ime, razr, od, oc));
- cbIzbor.addItem(pr+" "+ime);
- }
- fr.close();
- }catch(Exception ee){
- }
- }
- public void actionPerformed(ActionEvent e){
- int rb;
- rb = cbIzbor.getSelectedIndex();
- Ucenik u = vecu.elementAt(rb);
- tfPrezime.setText(u.getPrezime());
- tfIme.setText(u.getIme());
- tfRazred.setText(Integer.toString(u.getRazred()));
- tfOdeljenje.setText(Character.toString(u.getOdeljenje()));
- for(int k = 0; k < 5; k++)
- tfOcene[k].setText(Integer.toString(u.getOcena[k]));
- }
- public static void main(String[] args) {
- WinUcenici w = new WinUcenici();
- w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement