Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
package view;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ChildWindow {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;
public ChildWindow(){
prepareGUI();
}
public static void main(String[] args){
ChildWindow ChildWindow = new ChildWindow();
ChildWindow.showButtonDemo();
}
private void prepareGUI(){
mainFrame = new JFrame("Child");
mainFrame.getContentPane().setBackground(new Color(149, 32, 216));
mainFrame.setSize(400,250);
//need to set this to null and position everything manually
mainFrame.setLayout(new GridLayout(3, 1));
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
headerLabel = new JLabel("", JLabel.CENTER);
headerLabel.setFont(headerLabel.getFont().deriveFont(Font.BOLD, 16f));
statusLabel = new JLabel("",JLabel.CENTER);
statusLabel.setSize(350,100);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(new Color(149, 32, 216));
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private void showButtonDemo(){
headerLabel.setText("Child");
statusLabel.setText("You have a child!");
//resources folder should be inside SWING folder.
JButton Child = new JButton("Exit");
Child.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
statusLabel.setText("");
System.exit(0);
}
});
controlPanel.add(Child);
mainFrame.setVisible(true);
}
}