Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create CharityCard.java
This is the charity card pop up
  • Loading branch information
vip14008 committed Apr 7, 2017
1 parent 4260e1a commit 669e310
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions src/view/CharityCard.java
@@ -0,0 +1,94 @@
package view;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CharityCard {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;

public CharityCard(){
prepareGUI();
}
public static void main(String[] args){
CharityCard CharityCard = new CharityCard();
CharityCard.showButtonDemo();
}
private void prepareGUI(){
mainFrame = new JFrame("Charity");
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);
//new statuslabel of "10% of your whatever is XX dollars"
statusLabel.setSize(350,100);

controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());

mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private static ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL = CharityCard.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
private void showButtonDemo(){
headerLabel.setText("Charity!");
statusLabel.setText("Charity description");

//resources folder should be inside SWING folder.
ImageIcon icon = createImageIcon("/resources/java_icon.png","Java");

JButton Donate = new JButton("Donate");

JButton DontDonate = new JButton("Don't Donate", icon);
DontDonate.setHorizontalTextPosition(SwingConstants.LEFT);

Donate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//put message that they donated xx dollars after 10 seconds, close window
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

statusLabel.setText("Good Job! You donated all your savings!");


System.exit(0);
}
});

DontDonate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//put message that they are greedy. after 10 seconds, close window
System.exit(0);
}
});
controlPanel.add(Donate);

controlPanel.add(DontDonate);

mainFrame.setVisible(true);
}
}

1 comment on commit 669e310

@vip14008
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eclipse hates me so I can't push anything so I did this instead

Please sign in to comment.