Creating a JFrame and JLabel in Java Swings: Properties and Methods - Prof. Gore, Summaries of Information Integration

Information on creating a JFrame and setting its properties such as title, size, background color, and adding components like JLabel using different constructors and methods. It also covers creating a JLabel with text, image, or both, setting text alignment, font, color, and border. Both JFrame and JLabel are essential components in Java Swings for creating graphical user interfaces.

Typology: Summaries

2021/2022

Uploaded on 10/28/2022

sheena-rom
sheena-rom 🇵🇭

5 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JAVA SWINGS
JFrame
JFrame frame = new Jframe();
Constructor
JFrame(GraphicsConfiguration gc)
JFrame (String title, GraphicsConfiguration gc)
Methods
.setTitle("Title");
.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
.setDefaultCloseOperation(Jframe.HIDE_ON_CLOSE);
DO_NOTHING_ON CLOSE
.setResizable(false);
.setSize(420, 420);
ImageIcon image = new ImageIcon("logo.jpg");
.setIconImage(image.getImage());
.getContentPane().setBackground(new Color(0,0,0));
.getContentPane().setBackground(Color.black);
.add
.setLayout(null)
.pack();
.setExtendedState(Jframe.MAXIMIZED_BOTH);
.setLocationRelativeTo(null);
.addImpl(Component comp, Object constraints, int index);
.createRootPane();
.frameInit()
.setContentPane(Containe contentPane)
.setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
.setJMenuBar(JMenuBar menubar)
.setLayeredPane(JLayeredPane layeredPane)
.getRootPane()
.getTransferHandler()
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Creating a JFrame and JLabel in Java Swings: Properties and Methods - Prof. Gore and more Summaries Information Integration in PDF only on Docsity!

JFrame JFrame frame = new Jframe(); Constructor JFrame(GraphicsConfiguration gc) JFrame (String title, GraphicsConfiguration gc) Methods .setTitle("Title"); .setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); .setDefaultCloseOperation(Jframe.HIDE_ON_CLOSE); DO_NOTHING_ON CLOSE .setResizable(false); .setSize(420, 420); ImageIcon image = new ImageIcon("logo.jpg"); .setIconImage(image.getImage()); .getContentPane().setBackground(new Color(0,0,0)); .getContentPane().setBackground(Color.black); .add .setLayout(null) .pack(); .setExtendedState(Jframe.MAXIMIZED_BOTH); .setLocationRelativeTo(null); .addImpl(Component comp, Object constraints, int index); .createRootPane(); .frameInit() .setContentPane(Containe contentPane) .setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated) .setJMenuBar(JMenuBar menubar) .setLayeredPane(JLayeredPane layeredPane) .getRootPane() .getTransferHandler()

JFrame me frame = new Jframe(); Description frame in specified graphics config of screen device and blank title combined Description sets title of frame exit out of application hide out of application prevent frame from being resized sets x-dimension & y-dimension of frame create image icon changes icon of the frame changes color of frame background adds components in the frame does not display the layout - set bounds of label leaves the frame layout manager in charge Border border = BorderFactory.createLi maximizes the screen of the frame frame always open at the center add specified child component create a default rootpane Called by the constructors to init the JFrame properly. sets the contentPane property AndFeelDecorated) sets the menubar for this frame sets the layeredPane property. returns the rootPane object for this frame. gets the transferHandler property.

JLabel xt, image, or both, placing text in a container label = new Jlabel(); Description with the specified text. with the specified image. with the specified text, image, and horizontal alignment. Description set text of label sets image label set text to LEFT, CENTER, RIGHT of text .setPreferredSize(new Dimension(size, size) TOP, CENTER, BOTTOM of text sets the color of the text sets the font, bold, italic, and size of text sets gap of text and image changes the bg color display the bg color creates border displays the border sets vertical position of icon & text within label sets horizontal position of icon & text within label set the bounds (area limit) of label

JA

JPanel simpliest container class, provide space which an app can attach components JPanel panel = new Jbutton(); Constructor Description JPanel(boolean is DoubleBuffered) JPanel with FlowLayout and the specified buffering strategy. JPanel(LayoutManager layout) JPanel with the specified layout manager Methods Description .setBackground(Color.green); changes the color bg of panel .setBounds(); sets the x, y, width, height bounds .add() add components in panel .setPreferredSize(new Dimension(size, size)); resizes the panel

NGS

JButton creates button utton button = new Jbutton(); Description button with the specified text button with the specified icon object Constructor allows the button to be responsive add text to the button returns the text of the button removes the border once clicked adds icon to the button to get the Icon of the button removes the border of the text in the button gap between icon and text changes the color of the text in the button changes the bg of the button add border of button enable or disable button sets the mnemonic on the button

JPasswordField text component specialized for password entry JPasswordField value = new JPasswordField(); Constructor JPasswordField(int columns) JPasswordField(String text) JPasswordField(String text, int columns) Methods .setBackground();

JTextField textbox component used to add, set, or get text JTextField textField = new JTextField(); Constructor JTextField(String text) JTextField(String text, int columns) JTextField(int columns) Methods .setPrefferedSize(new Dimension (0, 0)); .add(textField); .setFont(new Font("Font Name", FONT.STYLE, size); .setForeground(Color.color); .addActionListener(ActionListener b); .setCaretColor(); .setText(); .setEditable(boolean); .getAction(); .removeActionListener(ActionListener b);

TextField t used to add, set, or get text Field = new JTextField(); Description text field with specified text textfield with specified text and columns empty textfield with specified number of columns Description custom size adds textfied in the before (before packing) changes the font receive action events from this textfield. changes the blinking line color adds text in the textfield if the text in the textfield can be edited or not s the currently set Action for this ActionEvent source, or null if no Action is set. specified action listener so that it no longer receives action events from this textfield

BorderLayout s in N,S,W,E and Center of a container va.awt.BorderLayout; places the panel to south rgins, 20 is horizontal, 15 is vertical