Created
April 30, 2014 19:07
-
-
Save xAIdrian/7df67d3f733f6f317b23 to your computer and use it in GitHub Desktop.
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
//Authored by: Adrian and Charlie | |
package stopwatch; | |
import java.awt.BorderLayout; | |
import java.awt.Component; | |
import java.awt.FlowLayout; | |
import java.awt.GridLayout; | |
import java.awt.event.KeyEvent; | |
import javax.swing.ButtonGroup; | |
import javax.swing.JButton; | |
import javax.swing.JFormattedTextField; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import javax.swing.JRadioButton; | |
import javax.swing.JSpinner; | |
import javax.swing.SpinnerListModel; | |
public class gooey extends JPanel | |
{ | |
//global variables | |
JPanel rootBorder = new JPanel(new BorderLayout()); | |
JPanel rootCenter = new JPanel(new GridLayout(2,1)); | |
JPanel gridTopBorder = new JPanel(new BorderLayout()); | |
JPanel gridBottomBorder = new JPanel(new BorderLayout()); | |
JPanel topCenterGrid = new JPanel(new GridLayout(1,2)); | |
JPanel leftGridBorder = new JPanel(new BorderLayout()); | |
JPanel rightGridGrid = new JPanel(new GridLayout(4,2)); | |
JPanel bottomBorderBorder = new JPanel(new BorderLayout()); | |
JPanel bottomBorderNorth = new JPanel(new FlowLayout()); | |
JPanel bottomBorderSouth = new JPanel(new FlowLayout()); | |
JPanel centerBorderSouth = new JPanel(new FlowLayout()); | |
JPanel finalFlow = new JPanel(new FlowLayout()); | |
//constuctor | |
public gooey() | |
{ | |
rootBorderLayout(); | |
add(rootBorder); | |
} | |
//additional methods | |
public void rootBorderLayout() | |
{ | |
JLabel title = new JLabel("Hanover Stopwatch", JLabel.CENTER); | |
rootBorder.add(title, BorderLayout.PAGE_START); | |
JButton notTitle = new JButton("Store"); | |
rootBorder.add(notTitle, BorderLayout.PAGE_END); | |
rootCenterLayout(); | |
rootBorder.add(rootCenter, BorderLayout.CENTER); | |
} | |
public void rootCenterLayout() | |
{ | |
gridTopBorderLayout(); | |
rootCenter.add(gridTopBorder); | |
gridBottomBorderLayout(); | |
rootCenter.add(gridBottomBorder); | |
} | |
public void gridTopBorderLayout() | |
{ | |
topCenterGridLayout(); | |
gridTopBorder.add(topCenterGrid, BorderLayout.CENTER); | |
JButton start = new JButton("Start"); | |
gridTopBorder.add(start, BorderLayout.PAGE_END); | |
} | |
public void gridBottomBorderLayout() | |
{ | |
bottomBorderNorthLayout(); | |
gridBottomBorder.add(bottomBorderNorth, BorderLayout.PAGE_START); | |
bottomBorderBorderLayout(); | |
gridBottomBorder.add(bottomBorderBorder, BorderLayout.CENTER); | |
bottomBorderSouthLayout(); | |
gridBottomBorder.add(bottomBorderSouth, BorderLayout.PAGE_END); | |
} | |
public void topCenterGridLayout() | |
{ | |
leftGridBorderLayout(); | |
topCenterGrid.add(leftGridBorder); | |
rightGridGridLayout(); | |
topCenterGrid.add(rightGridGrid); | |
} | |
public void leftGridBorderLayout() | |
{ | |
JFormattedTextField timer = new JFormattedTextField("the timer"); | |
leftGridBorder.add(timer, BorderLayout.CENTER); | |
JFormattedTextField wallclock = new JFormattedTextField("wall clock"); | |
leftGridBorder.add(wallclock, BorderLayout.PAGE_END); | |
} | |
public void rightGridGridLayout() | |
{ | |
JLabel sLap1 = new JLabel("Lap 1"); | |
rightGridGrid.add(sLap1); | |
JFormattedTextField lap1 = new JFormattedTextField(" "); | |
rightGridGrid.add(lap1); | |
JLabel sLap2 = new JLabel("Lap 2"); | |
rightGridGrid.add(sLap2); | |
JFormattedTextField lap2 = new JFormattedTextField(" "); | |
rightGridGrid.add(lap2); | |
JLabel sLap3 = new JLabel("Lap 3"); | |
rightGridGrid.add(sLap3); | |
JFormattedTextField lap3 = new JFormattedTextField(" "); | |
rightGridGrid.add(lap3); | |
JLabel sLap4 = new JLabel("Lap 4"); | |
rightGridGrid.add(sLap4); | |
JFormattedTextField lap4 = new JFormattedTextField(" "); | |
rightGridGrid.add(lap4); | |
} | |
public void finalFlowLayout() | |
{ | |
JRadioButton mon = new JRadioButton("Mon"); | |
mon.setMnemonic(KeyEvent.VK_B); | |
mon.setActionCommand("Mon"); | |
mon.setSelected(true); | |
JRadioButton tues = new JRadioButton("Tues"); | |
tues.setMnemonic(KeyEvent.VK_B); | |
tues.setActionCommand("Tues"); | |
JRadioButton wed = new JRadioButton("Wed"); | |
wed.setMnemonic(KeyEvent.VK_B); | |
wed.setActionCommand("Wed"); | |
JRadioButton thurs = new JRadioButton("Thurs"); | |
thurs.setMnemonic(KeyEvent.VK_B); | |
thurs.setActionCommand("Thurs"); | |
JRadioButton fri = new JRadioButton("Fri"); | |
fri.setMnemonic(KeyEvent.VK_B); | |
fri.setActionCommand("Fri"); | |
JRadioButton sat = new JRadioButton("Sat"); | |
sat.setMnemonic(KeyEvent.VK_B); | |
sat.setActionCommand("Sat"); | |
JRadioButton sun = new JRadioButton("Sun"); | |
sun.setMnemonic(KeyEvent.VK_B); | |
sun.setActionCommand("Sun"); | |
ButtonGroup group = new ButtonGroup(); | |
group.add(mon); | |
group.add(tues); | |
group.add(wed); | |
group.add(thurs); | |
group.add(fri); | |
group.add(sat); | |
group.add(sun); | |
finalFlow.add(mon); | |
finalFlow.add(tues); | |
finalFlow.add(wed); | |
finalFlow.add(thurs); | |
finalFlow.add(fri); | |
finalFlow.add(sat); | |
finalFlow.add(sun); | |
//add action listener | |
} | |
public void bottomBorderBorderLayout() | |
{ | |
centerBorderSouthLayout(); | |
bottomBorderBorder.add(centerBorderSouth, BorderLayout.PAGE_END); | |
JLabel daysOweek = new JLabel("Day of the Week:", JLabel.CENTER); | |
bottomBorderBorder.add(daysOweek, BorderLayout.PAGE_START); | |
finalFlowLayout(); | |
bottomBorderBorder.add(finalFlow, BorderLayout.CENTER); | |
} | |
public void bottomBorderNorthLayout() | |
{ | |
JButton lap = new JButton(" Lap "); | |
bottomBorderNorth.add(lap); | |
JButton clear = new JButton("Clear"); | |
bottomBorderNorth.add(clear); | |
} | |
public void bottomBorderSouthLayout() | |
{ | |
JLabel name = new JLabel("Name"); | |
bottomBorderSouth.add(name); | |
JFormattedTextField nameplace = new JFormattedTextField(" "); | |
bottomBorderSouth.add(nameplace); | |
} | |
public void centerBorderSouthLayout() | |
{ | |
JLabel year = new JLabel("month"); | |
centerBorderSouth.add(year); | |
String[] months = { | |
"Jan", "FEB", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "SEP", "Oct", "Nov", "Dec" | |
}; | |
SpinnerListModel monthmodel = new SpinnerListModel(months); | |
JSpinner monthSpinner = new JSpinner(monthmodel); | |
centerBorderSouth.add(monthSpinner); | |
JLabel day = new JLabel("day"); | |
centerBorderSouth.add(day); | |
String[] days = { | |
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", | |
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" | |
}; | |
SpinnerListModel daymodel = new SpinnerListModel(days); | |
JSpinner daySpinner = new JSpinner(daymodel); | |
centerBorderSouth.add(daySpinner); | |
} | |
//main | |
public static void main(String[] args) | |
{ | |
JFrame frame = new JFrame("hanover stopwatch"); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
JPanel gooey2 = new gooey(); | |
frame.getContentPane().add(gooey2); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment