From 345d0f57d4598e346c6976c3dee6d9c3bf6c8bc5 Mon Sep 17 00:00:00 2001 From: Sara S Saulat Date: Fri, 7 Apr 2017 12:09:55 -0400 Subject: [PATCH] Create ChildCard.java --- src/view/ChildCard.java | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/view/ChildCard.java diff --git a/src/view/ChildCard.java b/src/view/ChildCard.java new file mode 100644 index 0000000..19eec34 --- /dev/null +++ b/src/view/ChildCard.java @@ -0,0 +1,71 @@ +package view; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class ChildCard { + + private JFrame mainFrame; + private JLabel headerLabel; + private JLabel statusLabel; + private JPanel controlPanel; + + public ChildCard(){ + prepareGUI(); + } + public static void main(String[] args){ + ChildCard ChildCard = new ChildCard(); + ChildCard.showButtonDemo(); + } + private void prepareGUI(){ + mainFrame = new JFrame("Child"); + 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); + statusLabel = new JLabel("",JLabel.CENTER); + statusLabel.setSize(350,100); + + controlPanel = new JPanel(); + controlPanel.setLayout(new FlowLayout()); + + 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); + } +}