PDA

View Full Version : [java] colore


jalexb
12-06-2008, 15:49
import javax.swing.JFrame;
import javax.swing.JOptionPane;

class graf
{
public static void main(String args[])
{
String input=JOptionPane.showInputDialog("ecco il mio primo inserimento");
//int choice=Integer.parseInt(input);
//Shapes panel = new Shapes(choice);
JFrame application=new JFrame(); //crea il frame principale
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //chiude il frame
application.setSize(300,300); // attributi dell'istanza "application"
application.setVisible(true);
application.setTitle(input);
application.setLocation(300,300);
}
}

Vorrei dare un colore allo sfondo del Frame.....come posso fare?

banryu79
12-06-2008, 17:12
Ciao,
se consulti i Javadoc puoi vedere come JFrame (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFrame.html)erediti dalla classe Component:

java.lang.Object
extended by java.awt.Component
extended by java.awt.Container
extended by java.awt.Window
extended by java.awt.Frame
extended by javax.swing.JFrame


Component espone un metodo pubblico .setBackground(Color c) che accetta un riferimento ad un oggetto di tipo Color, e tu puoi invocare questo metodo per settare a piacere il colore di sfondo.