{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Frame frame is the basis to contain other user

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: at is not contained inside another window. Frame Frame is the basis to contain other user interface components in Java GUI applications. For For Swing GUI programs, use JFrame class to create widows. javax.swing.JFrame +JFrame() +JFrame(title: String) +setSize(width: int, height: int): void +setLocation(x: int, y: int): void +setVisible(visible: boolean): void +setDefaultCloseOperation(mode: int): void +setLocationRelativeTo (c: Component): void Creates a default frame with no title. Creates a frame with the specified title. Specifies the size of the frame. Specifies the upper-left corner location of the frame. Sets true to display the frame. Specifies the operation when the frame is closed. Sets the location of the frame relative to the specified component. If the component is null, the frame is centered on the screen. EE3206/EE5805 Java Programming & Applications 10 Creating Creating Frames import javax.swing.*; public class MyFrame { MyFrame public static void main(String args) { JFrame frame = new JFrame("Test Frame"); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } To add a button into the frame frame.add(new JButton("OK")); MyFrameWithComponents EE3206/EE5805 Java Programming & Applications 11 Layout Layout Managers Java Java’s layout managers provide a level of abstraction to automatically map your user interface on all window systems. systems. The The UI components are placed in containers. Each container has a layout manager to arrange the UI components within the container. Layout Layout managers are set in containers using the setLayo...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online