Extras din curs
Clasa Window
Clasa Window este rar utilizata în mod direct. Ea permite crearea unor ferestre top-level care nu au chenar si nici bara de meniuri. Pentru a crea ferestre mai complexe se utilizeaza clasele Frame si Dialog.
Constructor
Window (Frame)
Constructs a new Window initialized to an invisible state.
Metode
addNotify () Creates the Window's peer.
dispose()
{terge o fereastra de care nu mai este nevoie. Trebuie apelata pentru a elibera resursele
getToolkit() Returns the toolkit of this frame.
getWarningString() Gets the warning string for this window.
pack()
Redimensioneaza fereastra specifica corespunzator dimensiunilor componentelor sale
show()
Afiseaza fereastra specificata. In mod implicit, o fereastra nou creata nu este vizibila.
toBack()
Fereastra curenta este trimisa în spatele celorlate ferestre.
toFront()
Afiseaza fereastra specificata deasupra celorlalte ferestre.
Clasa Frame
Este o subclasa a clasei Window. Creeaza ferestre independente si functionale, continând bare de meniuri.
Variabile
CROSSHAIR_CURSOR
DEFAULT_CURSOR
E_RESIZE_CURSOR
HAND_CURSOR
MOVE_CURSOR
NE_RESIZE_CURSOR
NW_RESIZE_CURSOR
N_RESIZE_CURSOR
SE_RESIZE_CURSOR
SW_RESIZE_CURSOR
S_RESIZE_CURSOR
TEXT_CURSOR
WAIT_CURSOR
W_RESIZE_CURSOR
Constructori
Frame () Constructs a new Frame that is initially invisible.
Frame(String) Constructs a new, initially invisible Frame with the specified title.
Metode
addNotify () Creates the Frame's peer.
dispose() Disposes of the Frame.
getCursorType() Return the cursor type
getIconImage() Returns the icon image for this Frame.
getMenuBar() Gets the menu bar for this Frame.
getTitle() Gets the title of the Frame.
isResizable() Returns true if the user can resize the Frame.
paramString() Returns the parameter String of this Frame.
remove(MenuComponent) Removes the specified menu bar from this Frame.
setCursor(int) Set the cursor image to a predefined cursor.
setIconImage(Image) Sets the image to display when this Frame is iconized.
setMenuBar(MenuBar)Sets the menubar for this Frame to the specified menubar.
setResizable(boolean) Sets the resizable flag.
setTitle(String) Sets the title for this Frame to the specified title.
Exemplu - crearea si afisarea unei clase
import java.awt.*;
public class TestWindow {
public static void main(String argsst) {
Frame f = new Frame("Test Frame");
f.show();
}
}
Gestionarul implicit al clasei Window este BorderLayout. Din acest motiv, în momentul în care fereastra este creata dar nici o componenta grafica nu este pusa pe suprafata ei, suprafata de afisare a feretrei va fi nula.
Acelasi efect îl vom obtine daca o redimenionam si apelam apoi metoda pack() care determina dimeniunea suprafetei de afisare în functie de componentele grafice afisate pe ea.
Se observa de asemenea ca butoanele de maximizare, minimizare si închidere ale ferestrei nu sunt functionale. Aceasta deoarece, similar celorlalte butoane, ele genereaza niste evenimente care însa nu sunt receptionate de obiectul care reprezinta fereastra deoarece acesta nu s-a înregistrat ca ascultator. Interceptarea evenimentelor se face prin implementarea interfetei WindowListener si prin adaugarea în lista ascultatorilor ferestrei chiar a obiectului care implementeaza fereastra.
Preview document
Conținut arhivă zip
- Ferestre in Java.doc