18/09/08 23:56
xfiles
Salve , ho iniziato da poco a interessarmi del linguaggio Java e devo dire che lo trovo davvero interessante .....
Potreste aiutarmi a risolvere questo problema ?
In pratica devo creare una semplice finestra che visualizzi 15 - 20 righe di testo , ma tutti i miei tentativi sono falliti miseramente .
Se inserisco una sola riga va tutto bene , ma appena aggiungo le altre mi da errore , niente da fare !!!
Questo è il codice del programmino :
import java.awt.*;
import java.awt.event.*;
public class PrimaFinestra extends Frame
{
BorderLayout layout = new BorderLayout();
Panel contentPanel = new MyPanel();
Label messageLabel = new Label();
FrameListener frameListener = new FrameListener();
//** INIZIO CLASSI INTERNE PER LA GESTIONE EVENTI....
class FrameListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
//** FINE CLASSI INTERNE PER LA GESTIONE EVENTI....
public PrimaFinestra()
{
this.setTitle("Finestra AWT"
this.setSize(300, 60);
//***Definisco il posizionamento della finestra rispetto allo schermo ...
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int Altezza = d.height;
int Larghezza = d.width;
setLocation(Larghezza / 4, Altezza / 4);
// imposta il layout del Frame
this.setLayout(layout);
// Inizializza il testo della Label
messageLabel.setText("DA QUI' INIZIO A INSERIRE LE RIGHE DI TESTO "
// inserisce la Label nel Panel
contentPanel.add(messageLabel);
// inserisce il Panel nel Frame
this.add(contentPanel, BorderLayout.CENTER);
// assegna il listener al frame
this.addWindowListener(frameListener);
}
public static void main(String[] args)
{
Frame FirstWindow = new PrimaFinestra();
FirstWindow.show();
}
}
class MyPanel extends Panel
{
MyPanel()
{
FlowLayout layout = (FlowLayout)getLayout();
layout.setAlignment(FlowLayout.LEFT);
}
}
Ragazzo sei nei guai !!!!
Potreste aiutarmi a risolvere questo problema ?
In pratica devo creare una semplice finestra che visualizzi 15 - 20 righe di testo , ma tutti i miei tentativi sono falliti miseramente .
Se inserisco una sola riga va tutto bene , ma appena aggiungo le altre mi da errore , niente da fare !!!
Questo è il codice del programmino :
import java.awt.*;
import java.awt.event.*;
public class PrimaFinestra extends Frame
{
BorderLayout layout = new BorderLayout();
Panel contentPanel = new MyPanel();
Label messageLabel = new Label();
FrameListener frameListener = new FrameListener();
//** INIZIO CLASSI INTERNE PER LA GESTIONE EVENTI....
class FrameListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
//** FINE CLASSI INTERNE PER LA GESTIONE EVENTI....
public PrimaFinestra()
{
this.setTitle("Finestra AWT"
this.setSize(300, 60);
//***Definisco il posizionamento della finestra rispetto allo schermo ...
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int Altezza = d.height;
int Larghezza = d.width;
setLocation(Larghezza / 4, Altezza / 4);
// imposta il layout del Frame
this.setLayout(layout);
// Inizializza il testo della Label
messageLabel.setText("DA QUI' INIZIO A INSERIRE LE RIGHE DI TESTO "
// inserisce la Label nel Panel
contentPanel.add(messageLabel);
// inserisce il Panel nel Frame
this.add(contentPanel, BorderLayout.CENTER);
// assegna il listener al frame
this.addWindowListener(frameListener);
}
public static void main(String[] args)
{
Frame FirstWindow = new PrimaFinestra();
FirstWindow.show();
}
}
class MyPanel extends Panel
{
MyPanel()
{
FlowLayout layout = (FlowLayout)getLayout();
layout.setAlignment(FlowLayout.LEFT);
}
}
Ragazzo sei nei guai !!!!
Ultima modifica effettuata da xfiles 19/09/08 12:38
aaa