|
ButtonManager
> FinestraPrincipale > in depth
|
|
FinestraPrincipale
|
package buttonmanager;
import javax.swing.*;
import java.awt.*;
public class FinestraPrincipale extends JFrame{
public static void main(String[ ] a){
new FinestraPrincipale();
}
public FinestraPrincipale() {
this.setSize(400,400);
this.centerInScreen();
// fai in modo che la chiusura della finestra
// termini l'applicazione
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
//
this.setLayout(new BorderLayout());
//
ButtonPanel bp=new ButtonPanel();
this.add(bp,BorderLayout.CENTER);
this.add(new ControlPanel(bp),BorderLayout.SOUTH);
// rendi la finestra visibile
this.setVisible(true);
}
private void centerInScreen() {
// trova le dimensioni dello schermo e della finestra
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
// assicurati che la finestra non sia più grande dello schermo
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
// centra la finestra nello schermo
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
}
|
|
|