Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Potrebna pomoc oko CardLayouta

[es] :: Java :: Potrebna pomoc oko CardLayouta

[ Pregleda: 934 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Teslas
jfhjhm hg

Član broj: 97216
Poruke: 11
212.200.214.*



Profil

icon Potrebna pomoc oko CardLayouta30.03.2009. u 17:42 - pre 183 meseci
Potrebno je postaviti komponente pomocu GridBagLayout menadzera sto sam i uradio (Prozor sa imenom i prezimenom 2 labele i dva textfilda ima i dva dugmeta unesi i otkazi kada se pritisne unesi ceo prozor treba da se oboji u plavo a kada se klikne na otkazi da se zatvori prozor) Znam da to treba da se uradi pomocu CardLayouta da se naprave dve kartice ali nikako mi ne uspeva molim za pomoc?Nesto sam pokusavao ali za sada bezuspesno postavljam kod .Molim za pomoc.
import java.awt.event.ItemEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Prozor {
JPanel cards;
final static String Glavnipanel = ("prva");
final static String Unospanel = ("druga");
public static void addComponentsToPane( Container pane) {
JPanel cards;
JLabel label;
JLabel label2;
JTextField polje1;
JTextField polje2;
JButton button1;
JButton button2;
JPanel pCard = new JPanel();
pCard.setLayout(new GridBagLayout());
CardLayout c1= new CardLayout();
GridBagConstraints c = new GridBagConstraints();
label = new JLabel("Ime: ");
c.gridx = 0;
c.gridy = 0;
c.insets= new Insets(0,20,0,0);
pCard.add(label, c);
label2 = new JLabel("Prezime: ");
c.gridx = 0;
c.gridy = 1;
pCard.add(label2, c);
c.insets= new Insets(0,20,0,0);

polje1 = new JTextField(15);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 0;

c.insets= new Insets(10,0,5,40);
pCard.add(polje1,c);


polje2 = new JTextField(15);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 1;

c.insets= new Insets(10,0,5,40);
pCard.add(polje2,c);



button1= new JButton("Unesi");
c.gridx =1;
c.gridy=3;
c.insets= new Insets(5,10,10,160);
pCard.add(button1,c);

button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {

// c.setBackground(Color.BLUE);

}});

button2 = new JButton("Otkazi");
c.gridx =1;
c.gridy=3;
c.insets= new Insets(5,110,10,60);
pCard.add(button2,c);
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {


System.exit(0);
}
});

JPanel pCard1 = new JPanel();
pCard1.setBackground(Color.BLUE);
cards = new JPanel(new CardLayout());
cards.add(pCard, "prva");
cards.add(pCard1,"druga");
pane.add(cards,BorderLayout.CENTER);
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("[Proba]");
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(350,200);
frame.setLocationRelativeTo(null);
//Set up the content pane.
addComponentsToPane(frame.getContentPane());

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
 
Odgovor na temu

gajo2
Budapest

Član broj: 62614
Poruke: 518
*.i-rose.si.

Sajt: b.flyingoranges.com


+117 Profil

icon Re: Potrebna pomoc oko CardLayouta31.03.2009. u 07:07 - pre 183 meseci
Izvoli:

import java.awt.event.ItemEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Prozor {
final static String Glavnipanel = ("prva");
final static String Unospanel = ("druga");
public static void addComponentsToPane( Container pane) {
final CardLayout c1= new CardLayout();
final JPanel cards = new JPanel(c1);
JLabel label;
JLabel label2;
JTextField polje1;
JTextField polje2;
JButton button1;
JButton button2;
JPanel pCard = new JPanel();
pCard.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
label = new JLabel("Ime: ");
c.gridx = 0;
c.gridy = 0;
c.insets= new Insets(0,20,0,0);
pCard.add(label, c);
label2 = new JLabel("Prezime: ");
c.gridx = 0;
c.gridy = 1;
pCard.add(label2, c);
c.insets= new Insets(0,20,0,0);

polje1 = new JTextField(15);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 0;

c.insets= new Insets(10,0,5,40);
pCard.add(polje1,c);


polje2 = new JTextField(15);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 1;

c.insets= new Insets(10,0,5,40);
pCard.add(polje2,c);



button1= new JButton("Unesi");
c.gridx =1;
c.gridy=3;
c.insets= new Insets(5,10,10,160);
pCard.add(button1,c);

button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
c1.show(cards, "druga");
// c.setBackground(Color.BLUE);

}});

button2 = new JButton("Otkazi");
c.gridx =1;
c.gridy=3;
c.insets= new Insets(5,110,10,60);
pCard.add(button2,c);
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {


System.exit(0);
}
});

JPanel pCard1 = new JPanel();
pCard1.setBackground(Color.BLUE);
cards.add(pCard, "prva");
cards.add(pCard1,"druga");
pane.add(cards,BorderLayout.CENTER);
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("[Proba]");
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(350,200);
frame.setLocationRelativeTo(null);
//Set up the content pane.
addComponentsToPane(frame.getContentPane());

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
 
Odgovor na temu

Teslas
jfhjhm hg

Član broj: 97216
Poruke: 11
77.46.229.*



Profil

icon Re: Potrebna pomoc oko CardLayouta31.03.2009. u 19:54 - pre 183 meseci
Hvala mnogo na pomoci!!!!
 
Odgovor na temu

[es] :: Java :: Potrebna pomoc oko CardLayouta

[ Pregleda: 934 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.