1.1 Introducere in Java Swing Flashcards

1
Q

Cum se poate crea principala fereastra in Swing ?

A

JFrame frame = new JFrame();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Cati constructori are si ce accepta in constructori JFrame(); ?

A

Jframe accepta 3 constructori:

  • Titlul ferestrei
  • GraphicsConfiguration ( cu aceasta clasa se poate seta ca jframe sa se afiseze pe alt monitor )
  • Titlul ferestrei, GraphicsConfiguration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Detectarea si modificarea pozititei ferestrei JFrame se face cu metodele ?

A

getLocation() si setLocation();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Care este codul pentru afisarea unei ferestre de tip info message ?

A

JOptionPane.showMessageDialog(frame,”message”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Cum se poate seta dimensiunea ferestrei JFrame ?

A

frame.setSize(600,400);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Cum se poate prelua dimensiunea ferestrei JFrame?

A

frame.getSize().width, frame.getSize().height

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Fereastra JFrame nu va fii afisata decat daca ?

A

Se foloseste metoda frame.setVisible(true);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Cum putem sa distrugem fereastra JFrame?

A

folosind metoda dispose(); //frame.dispose();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Daca inchidem fereastra JFrame folosind butonul x, vom observa ca aplicatia va rula in continuare. Ce putem face ca aplicatia sa se inchida o data cu fereastra JFrame ?

A

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Cum se poate adauga sau scoate o componenta child de pe JFrame ?
Adauga pe frame un buton si apoi scoatel.

A

folosind metoda add() si remove();

JButton b = new JButton(“Test);

frame. add(b);
frame. remove(b);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Care este Layout-ul implicit a lui JFrame ?

A

BorderLayout.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Cu ce metoda se poate seta layout-ul ?

A

setLayout();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Schimbati layout-ul din BorderLayout in FlowLayout

A

frame. setLayout(new FlowLayout));

frame. add(new JButton(“Hello”));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Cum se poate localiza o componenta care a fost adaugata anonim in container ?

A

Folosind frame.getContentPane().getComponent(0);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Cum se foloseste cel mai des JFrame ?

Da-ti un ex:

A

Cel mai des JFrame va fii mostenita de o alta clasa.

Ex:
public class MyFrame extends JFrame {
    public MyFrame() {
        initComponents();
    }
    void initComponents() {
        this.setSize(600, 400);
        this.setVisible(true);
    }

}

//Main
public class MyApp {
    public static void main(String[] args)  {
        MyFrame mf = new MyFrame();
    }

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Folosind clasa MyFrame din exemplul anterior, desenati un String cu valoarea Hello pe locatia 200,200

A
@Override
public void paint(Graphics g)
 {
g.drawString("Hello", 200, 200);
}