Advertisement
Guest User

Untitled

a guest
May 24th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. package game1;
  2.  
  3. import java.awt.EventQueue;
  4. import javax.swing.JFrame;
  5. import javax.swing.JButton;
  6. import javax.swing.ImageIcon;
  7. import java.awt.Image;
  8. import javax.swing.SwingConstants;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.ActionEvent;
  13.  
  14. public class Frame1
  15. {
  16.  
  17.  
  18.  
  19. public JFrame frame;
  20. public JButton mainBttn;
  21.  
  22. /**
  23. * Launch the application.
  24. */
  25. public static void main(String[] args)
  26. {
  27.  
  28. EventQueue.invokeLater(new Runnable()
  29. {
  30. public void run()
  31. {
  32. try
  33. {
  34. Frame1 window = new Frame1();
  35. window.frame.setVisible(true);
  36. } catch (Exception e)
  37. {
  38. e.printStackTrace();
  39. }
  40. }
  41. });
  42. }
  43.  
  44. /**
  45. * Create the application.
  46. */
  47. public Frame1() {
  48. initialize();
  49. }
  50.  
  51. /**
  52. * Initialize the contents of the frame.
  53. */
  54.  
  55.  
  56.  
  57.  
  58. public void initialize() {
  59. frame = new JFrame();
  60. frame.setBounds(100, 100, 1200, 800);
  61. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  62. Image chocChip =new ImageIcon(this.getClass().getResource("/cookie.png")).getImage();
  63.  
  64.  
  65. frame.getContentPane().setLayout(null);
  66.  
  67. mainBttn = new JButton("");
  68. mainBttn.addActionListener(new ActionListener()
  69. {
  70. public void actionPerformed(ActionEvent arg0)
  71. {
  72.  
  73. }
  74. });
  75. mainBttn.addMouseListener(new MouseAdapter()
  76. {
  77. @Override
  78. public void mouseClicked(MouseEvent arg0)
  79. {
  80.  
  81. }
  82. });
  83. mainBttn.setBounds(239, 97, 393, 309);
  84. frame.getContentPane().add(mainBttn);
  85.  
  86. mainBttn.setHorizontalAlignment(SwingConstants.LEFT);
  87. mainBttn.setVerticalAlignment(SwingConstants.BOTTOM);
  88. mainBttn.setIcon(new ImageIcon(chocChip));
  89.  
  90. JButton storeBttn = new JButton("Store");
  91. storeBttn.addMouseListener(new MouseAdapter()
  92. {
  93. @Override
  94. public void mouseClicked(MouseEvent arg0)
  95. {
  96. Store newWindow = new Store();
  97. newWindow.setVisible(true);
  98. }
  99. });
  100. storeBttn.setBounds(77, 226, 89, 23);
  101. frame.getContentPane().add(storeBttn);
  102.  
  103. }
  104.  
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. package game1;
  122.  
  123. import java.awt.BorderLayout;
  124. import java.awt.FlowLayout;
  125.  
  126. import javax.swing.JButton;
  127. import javax.swing.JDialog;
  128. import javax.swing.JFrame;
  129. import javax.swing.JLabel;
  130. import javax.swing.JPanel;
  131. import javax.swing.border.EmptyBorder;
  132. import javax.swing.BoxLayout;
  133. import javax.swing.ImageIcon;
  134.  
  135. import java.awt.GridBagLayout;
  136. import java.awt.Image;
  137. import java.awt.GridBagConstraints;
  138. import java.awt.Insets;
  139. import java.awt.event.ActionListener;
  140. import java.awt.event.ActionEvent;
  141. import java.awt.Component;
  142. import javax.swing.Box;
  143. import java.awt.event.MouseAdapter;
  144. import java.awt.event.MouseEvent;
  145.  
  146. public class Store extends JDialog {
  147.  
  148. private final JPanel contentPanel = new JPanel();
  149. /**
  150. * Launch the application.
  151. */
  152. public static void main(String[] args)
  153. {
  154.  
  155.  
  156. try
  157. {
  158. Store dialog = new Store();
  159. dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  160. dialog.setVisible(true);
  161. } catch (Exception e) {
  162. e.printStackTrace();
  163. }
  164. }
  165.  
  166. /**
  167. * Create the dialog.
  168. */
  169. public Store()
  170. {
  171.  
  172. setBounds(100, 100, 821, 639);
  173. getContentPane().setLayout(new BorderLayout());
  174. contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
  175. getContentPane().add(contentPanel, BorderLayout.CENTER);
  176. contentPanel.setLayout(null);
  177. {
  178. JButton oatmealBttn = new JButton("");
  179. oatmealBttn.addMouseListener(new MouseAdapter()
  180. {
  181. @Override
  182. public void mouseClicked(MouseEvent arg0)
  183. {
  184.  
  185. }
  186. });
  187. oatmealBttn.setBounds(10, 11, 100, 100);
  188. contentPanel.add(oatmealBttn);
  189. Image oat =new ImageIcon(this.getClass().getResource("/oatmeal raisin.jpg")).getImage();
  190. oatmealBttn.setIcon(new ImageIcon(oat));
  191.  
  192. }
  193. {
  194. JButton chocoBttn = new JButton("");
  195. chocoBttn.setBounds(10, 122, 100, 100);
  196. contentPanel.add(chocoBttn);
  197. Image chocoChunk = new ImageIcon(this.getClass().getResource("/chocolate chunk.jpg")).getImage();
  198. chocoBttn.setIcon(new ImageIcon(chocoChunk));
  199. }
  200. {
  201. JButton mmBttn = new JButton("");
  202. mmBttn.setBounds(10, 233, 100, 100);
  203. contentPanel.add(mmBttn);
  204. Image mmCookie = new ImageIcon(this.getClass().getResource("/m&m.jpg")).getImage();
  205. mmBttn.setIcon(new ImageIcon(mmCookie));
  206. }
  207. {
  208. JButton macaroonBttn = new JButton("");
  209. macaroonBttn.setBounds(10, 344, 100, 100);
  210. contentPanel.add(macaroonBttn);
  211. Image macaroonC = new ImageIcon(this.getClass().getResource("/macaroon.png")).getImage();
  212. macaroonBttn.setIcon(new ImageIcon(macaroonC));
  213. }
  214. {
  215. JButton oreoBttn = new JButton("");
  216. oreoBttn.setBounds(10, 455, 100, 100);
  217. contentPanel.add(oreoBttn);
  218. Image oreoC = new ImageIcon(this.getClass().getResource("/oreo.jpg")).getImage();
  219. oreoBttn.setIcon(new ImageIcon(oreoC));
  220. }
  221. {
  222. JPanel buttonPane = new JPanel();
  223. buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
  224. getContentPane().add(buttonPane, BorderLayout.SOUTH);
  225. {
  226. JButton okButton = new JButton("OK");
  227. okButton.addMouseListener(new MouseAdapter()
  228. {
  229. @Override
  230. public void mouseClicked(MouseEvent e)
  231. {
  232.  
  233. }
  234. });
  235. okButton.setActionCommand("OK");
  236. buttonPane.add(okButton);
  237. getRootPane().setDefaultButton(okButton);
  238. }
  239. }
  240. }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement