Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Sunday 17 February 2019

Fourth week Term Work Program 2

2) Write a Java Program that creates a SWING window with the following attributes:
a. Dimensions of the window: 500X400
b. Initial position of the window: (150, 150)
c. Name of the window: My First SWING Frame
d. Add a button named “Cancel” to the window
e. On pressing “X” button, the window should hide


Program:
import java.awt.Frame;
import javax.swing.*;
public class swingfirst {
public static void main(String[] args) {
JFrame frame=new JFrame("My First Swing Frame");
frame.setSize(500, 400);
frame.setLocation(150, 150);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
JButton button=new JButton("Cancel");
frame.getContentPane().add(button);
frame.setVisible(true);
}

}
Output:


0 comments:

Post a Comment