Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.awt.BorderLayout;
  3. import java.awt.CardLayout;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.FlowLayout;
  8. import java.awt.Font;
  9. import java.awt.Graphics;
  10. import java.awt.Graphics2D;
  11. import java.awt.Image;
  12. import java.awt.Insets;
  13. import java.awt.Robot;
  14. import java.awt.Toolkit;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.event.ActionListener;
  17. import java.awt.event.InputEvent;
  18. import java.awt.event.MouseEvent;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.util.concurrent.TimeUnit;
  22.  
  23. import javax.imageio.ImageIO;
  24. import javax.swing.Action;
  25. import javax.swing.BorderFactory;
  26. import javax.swing.BoxLayout;
  27. import javax.swing.Icon;
  28. import javax.swing.ImageIcon;
  29. import javax.swing.JButton;
  30. import javax.swing.JComponent;
  31. import javax.swing.JFrame;
  32. import javax.swing.JLabel;
  33. import javax.swing.JPanel;
  34. import javax.swing.SwingConstants;
  35. import javax.swing.Timer;
  36. import javax.swing.WindowConstants;
  37.  
  38. public class Welcome extends JFrame {
  39. JLabel label1;
  40. JPanel LeftPanel;
  41. JPanel panel2;
  42. JPanel panelfinal;
  43. JPanel other;
  44. ImageIcon image;
  45. Image background;
  46. JButton play;
  47. JButton tutorial;
  48. Image img;
  49. Graphics2D g2;
  50. Timer myTimer;
  51. static int count = 0;
  52. private static Robot robot=null;
  53.  
  54.  
  55. public static void Klick (int x, int y) {
  56. robot.mouseMove(x, y);
  57. robot.mousePress(MouseEvent.BUTTON1_MASK);
  58. }
  59. public Welcome() throws IOException {
  60.  
  61. // label1-image>>
  62. label1 = new JLabel();
  63. image = new ImageIcon(ImageIO.read(Welcome.class.getResourceAsStream("biodiversity_illy_bees.v1 (1).jpeg")));
  64. System.out.println(image);
  65. label1.setIcon(image);
  66.  
  67. LeftPanel = new JPanel(new CardLayout());
  68. LeftPanel.add(label1, "picture");
  69. LeftPanel.add(new LeftPanel(), "tutorial");
  70.  
  71. this.add(new buttons(), BorderLayout.EAST);
  72. this.add(LeftPanel);
  73.  
  74. // frame
  75. setSize(1000, 650);
  76. setVisible(true);
  77. setTitle("BEE");
  78. setResizable(false);
  79. setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  80.  
  81. myTimer = new Timer(20, new ActionListener() {
  82. public void actionPerformed(ActionEvent evt) {
  83. CardLayout cl = (CardLayout) (LeftPanel.getLayout());
  84. if (buttons.tutorialClicked == true) {
  85. cl.show(LeftPanel, "tutorial");
  86. buttons.tutorialClicked = false;
  87. }
  88. if ((buttons.playClicked == true)) {
  89. cl.show(LeftPanel, "picture");
  90. buttons.playClicked = false;
  91. repaint();
  92. }
  93. }
  94. });
  95. myTimer.start();
  96. }
  97.  
  98. public void paint(Graphics g) {
  99. super.paint(g);
  100. Graphics2D g2 = (Graphics2D) g;
  101. g2.setFont(new Font("Arial Rounded MT Bold", Font.ITALIC, 70));
  102. g2.drawString("BEE ", 40, 110);
  103. g2.drawString("RUN", 100, 200);
  104. }
  105.  
  106. public static void main(String[] args) throws IOException {
  107.  
  108.  
  109. javax.swing.SwingUtilities.invokeLater(new Runnable() {
  110. public void run() {
  111. try {
  112. new Welcome();
  113. robot=new Robot();
  114. } catch (IOException e) {
  115. } catch (AWTException e) {
  116. }
  117. Klick(900,450);
  118. }
  119. });
  120. }
  121. }
  122.  
  123. class buttons extends JPanel implements ActionListener {
  124. JPanel panel2;
  125. JButton play;
  126. JButton tutorial;
  127. JPanel space1;
  128. JPanel space2;
  129. JPanel space3;
  130. ImageIcon imageIcon;
  131. static boolean tutorialClicked = false;
  132. static boolean playClicked = false;
  133.  
  134.  
  135. public buttons() throws IOException {
  136. // button-play>>
  137.  
  138. play = new JButton("PLAY");
  139. play.setOpaque(true);
  140. play.setBorderPainted(false);
  141. play.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 30));
  142. play.addActionListener(this);
  143. play.setActionCommand("play");
  144. imageIcon = new ImageIcon(ImageIO.read(Welcome.class.getResourceAsStream("Hive2.jpeg")));
  145. play.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 30));
  146. Image image = imageIcon.getImage(); // transform it
  147. Image newimg = image.getScaledInstance(160, 140, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
  148. imageIcon = new ImageIcon(newimg); // transform it back
  149. play.setIcon(imageIcon);
  150. play.setHorizontalTextPosition(JButton.CENTER);
  151. play.setVerticalTextPosition(JButton.CENTER);
  152.  
  153. // button-tutorial>>
  154. tutorial = new JButton("TUTORIAL");
  155. tutorial.setOpaque(true);
  156. tutorial.setBorderPainted(false);
  157. tutorial.setFont(new Font("Arial Rounded MT Bold", Font.BOLD, 30));
  158. tutorial.addActionListener(this);
  159. tutorial.setActionCommand("tutorial");
  160. tutorial.setIcon(imageIcon);
  161. tutorial.setHorizontalTextPosition(JButton.CENTER);
  162. tutorial.setVerticalTextPosition(JButton.CENTER);
  163. tutorial.requestFocus();
  164.  
  165. // panel space>>
  166. space1 = new JPanel();
  167. space1.setPreferredSize(new Dimension(50, 102));
  168. // panel space>>
  169. space2 = new JPanel();
  170. space2.setPreferredSize(new Dimension(50, 110));
  171.  
  172. // panel space>>
  173. space3 = new JPanel();
  174. space3.setPreferredSize(new Dimension(50, 200));
  175.  
  176. // panel2>>
  177. panel2 = new JPanel();
  178. panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
  179. panel2.add(space1);
  180. panel2.add(play);
  181. panel2.add(space2);
  182. panel2.add(tutorial);
  183. panel2.add(space3);
  184. this.add(panel2);
  185. }
  186.  
  187. public void paint(Graphics g) {
  188. super.paint(g);
  189. Graphics2D g2 = (Graphics2D) g;
  190. Color Background = new Color(255, 110, 0);
  191. g2.setColor(Background);
  192. g2.fillRect(0, 0, 300, 650);
  193. Color border = new Color(225, 210, 0);
  194. g2.setColor(border);
  195. g2.fillRect(5, 102, 188, 164);
  196. g2.fillRect(5, 362, 188, 164);
  197. g2.setColor(Color.BLACK);
  198. g2.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 30));
  199. g2.drawString("MENU:", 20, 50);
  200. }
  201.  
  202. @Override
  203. public void actionPerformed(ActionEvent evt) {
  204. if (evt.getActionCommand().equals("play")) {
  205. playClicked = true;
  206. }
  207. if (evt.getActionCommand().equals("tutorial")) {
  208. tutorialClicked = true;
  209. }
  210. }
  211.  
  212. public static boolean getPlayClicked() {
  213. return playClicked;
  214. }
  215.  
  216. public static boolean getTutorialClicked() {
  217. return tutorialClicked;
  218. }
  219. }
  220.  
  221. class LeftPanel extends JPanel {
  222. JLabel label1;
  223. ImageIcon image;
  224.  
  225. LeftPanel() throws IOException {
  226. this.setLayout(null);
  227. this.setBounds(0, 0, 800, 650);
  228.  
  229. }
  230.  
  231. public void paint(Graphics g) {
  232. super.paint(g);
  233. Graphics2D g2 = (Graphics2D) g;
  234. Color Border = new Color(225, 210, 0);
  235. g2.setColor(Border);
  236. g2.fillRect(0, 0, 800, 650);
  237. Color Background = new Color(255, 110, 0);
  238. g2.setColor(Background);
  239. g2.fillRect(10, 10, 770, 610);
  240. g2.setColor(Color.BLACK);
  241. g2.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 50));
  242. g2.drawString("HOW TO PLAY", 50, 100);
  243. }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement