Permalink
Cannot retrieve contributors at this time
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?
2102-Group-Project-Spring-2017/src/view/CharityWindow.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
140 lines (106 sloc)
3.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class CharityWindow { | |
private JFrame mainFrame; | |
private JLabel headerLabel; | |
private JLabel statusLabel; | |
private JPanel controlPanel; | |
public boolean doesDonate; | |
public boolean hasAnswered = false; | |
public CharityWindow(){ | |
prepareGUI(); | |
} | |
public static void main(String[] args){ | |
CharityWindow CharityWindow = new CharityWindow(); | |
boolean b = CharityWindow.showButtonDemo(); | |
System.out.println(b); | |
} | |
private void prepareGUI(){ | |
mainFrame = new JFrame("Charity"); | |
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); | |
//new statuslabel of "10% of your whatever is XX dollars" | |
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); | |
} | |
public boolean showButtonDemo(){ | |
headerLabel.setText("Charity!"); | |
statusLabel.setText("Charity description"); | |
//resources folder should be inside SWING folder. | |
JButton Donate = new JButton("Donate"); | |
JButton DontDonate = new JButton("Don't Donate"); | |
DontDonate.setHorizontalTextPosition(SwingConstants.LEFT); | |
Donate.addMouseListener(new MouseListener() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
// TODO Auto-generated method stub | |
hasAnswered = true; | |
doesDonate = true; | |
mainFrame.dispose(); | |
} | |
@Override | |
public void mousePressed(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void mouseReleased(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void mouseEntered(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void mouseExited(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
}); | |
DontDonate.addMouseListener(new MouseListener() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
// TODO Auto-generated method stub | |
hasAnswered = true; | |
doesDonate = false; | |
mainFrame.dispose(); | |
} | |
@Override | |
public void mousePressed(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void mouseReleased(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void mouseEntered(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void mouseExited(MouseEvent e) { | |
// TODO Auto-generated method stub | |
} | |
}); | |
controlPanel.add(Donate); | |
controlPanel.add(DontDonate); | |
mainFrame.setVisible(true); | |
return doesDonate; | |
} | |
} |