JFrame constructors:
-JFrame()
creates a new invisible window.
-Frame(String title)
creates anew invisible window with specified title.
Its useful methods:
-getContentPane()
returns the contentPane object of the window.
-setDefaultCloseOperation(int operation)
sets the defaut close operation of the window.
-setJMenuBar(JMenuBar menu)
sets the menu bar to the window.
-setIconImage(Image img)
sets the image icon of the window.
Example:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
class Show extends JFrame{
Show(String title){
setTitle(title);
setSize(400,300);
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image img=Toolkit.getDefaultToolkit().getImage("d:/icon.png");
setIconImage(img);
Container contpane=getContentPane();
//code add components to the content pane
setVisible(true);
}
}
public class JFrameSwing {
public static void main(String[] args){
new Show("JFrame");
}
}
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
class Show extends JFrame{
Show(String title){
setTitle(title);
setSize(400,300);
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image img=Toolkit.getDefaultToolkit().getImage("d:/icon.png");
setIconImage(img);
Container contpane=getContentPane();
//code add components to the content pane
setVisible(true);
}
}
public class JFrameSwing {
public static void main(String[] args){
new Show("JFrame");
}
}
No comments:
Post a Comment