Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AWTException;
- import java.awt.BorderLayout;
- import java.awt.CardLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Insets;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.InputEvent;
- import java.awt.event.MouseEvent;
- import java.io.File;
- import java.io.IOException;
- import java.util.concurrent.TimeUnit;
- import javax.imageio.ImageIO;
- import javax.swing.Action;
- import javax.swing.BorderFactory;
- import javax.swing.BoxLayout;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComponent;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.SwingConstants;
- import javax.swing.Timer;
- import javax.swing.WindowConstants;
- public class Welcome extends JFrame {
- JLabel label1;
- JPanel LeftPanel;
- JPanel panel2;
- JPanel panelfinal;
- JPanel other;
- ImageIcon image;
- Image background;
- JButton play;
- JButton tutorial;
- Image img;
- Graphics2D g2;
- Timer myTimer;
- static int count = 0;
- private static Robot robot=null;
- public static void Klick (int x, int y) {
- robot.mouseMove(x, y);
- robot.mousePress(MouseEvent.BUTTON1_MASK);
- }
- public Welcome() throws IOException {
- // label1-image>>
- label1 = new JLabel();
- image = new ImageIcon(ImageIO.read(Welcome.class.getResourceAsStream("biodiversity_illy_bees.v1 (1).jpeg")));
- System.out.println(image);
- label1.setIcon(image);
- LeftPanel = new JPanel(new CardLayout());
- LeftPanel.add(label1, "picture");
- LeftPanel.add(new LeftPanel(), "tutorial");
- this.add(new buttons(), BorderLayout.EAST);
- this.add(LeftPanel);
- // frame
- setSize(1000, 650);
- setVisible(true);
- setTitle("BEE");
- setResizable(false);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- myTimer = new Timer(20, new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- CardLayout cl = (CardLayout) (LeftPanel.getLayout());
- if (buttons.tutorialClicked == true) {
- cl.show(LeftPanel, "tutorial");
- buttons.tutorialClicked = false;
- }
- if ((buttons.playClicked == true)) {
- cl.show(LeftPanel, "picture");
- buttons.playClicked = false;
- repaint();
- }
- }
- });
- myTimer.start();
- }
- public void paint(Graphics g) {
- super.paint(g);
- Graphics2D g2 = (Graphics2D) g;
- g2.setFont(new Font("Arial Rounded MT Bold", Font.ITALIC, 70));
- g2.drawString("BEE ", 40, 110);
- g2.drawString("RUN", 100, 200);
- }
- public static void main(String[] args) throws IOException {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- new Welcome();
- robot=new Robot();
- } catch (IOException e) {
- } catch (AWTException e) {
- }
- Klick(900,450);
- }
- });
- }
- }
- class buttons extends JPanel implements ActionListener {
- JPanel panel2;
- JButton play;
- JButton tutorial;
- JPanel space1;
- JPanel space2;
- JPanel space3;
- ImageIcon imageIcon;
- static boolean tutorialClicked = false;
- static boolean playClicked = false;
- public buttons() throws IOException {
- // button-play>>
- play = new JButton("PLAY");
- play.setOpaque(true);
- play.setBorderPainted(false);
- play.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 30));
- play.addActionListener(this);
- play.setActionCommand("play");
- imageIcon = new ImageIcon(ImageIO.read(Welcome.class.getResourceAsStream("Hive2.jpeg")));
- play.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 30));
- Image image = imageIcon.getImage(); // transform it
- Image newimg = image.getScaledInstance(160, 140, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
- imageIcon = new ImageIcon(newimg); // transform it back
- play.setIcon(imageIcon);
- play.setHorizontalTextPosition(JButton.CENTER);
- play.setVerticalTextPosition(JButton.CENTER);
- // button-tutorial>>
- tutorial = new JButton("TUTORIAL");
- tutorial.setOpaque(true);
- tutorial.setBorderPainted(false);
- tutorial.setFont(new Font("Arial Rounded MT Bold", Font.BOLD, 30));
- tutorial.addActionListener(this);
- tutorial.setActionCommand("tutorial");
- tutorial.setIcon(imageIcon);
- tutorial.setHorizontalTextPosition(JButton.CENTER);
- tutorial.setVerticalTextPosition(JButton.CENTER);
- tutorial.requestFocus();
- // panel space>>
- space1 = new JPanel();
- space1.setPreferredSize(new Dimension(50, 102));
- // panel space>>
- space2 = new JPanel();
- space2.setPreferredSize(new Dimension(50, 110));
- // panel space>>
- space3 = new JPanel();
- space3.setPreferredSize(new Dimension(50, 200));
- // panel2>>
- panel2 = new JPanel();
- panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
- panel2.add(space1);
- panel2.add(play);
- panel2.add(space2);
- panel2.add(tutorial);
- panel2.add(space3);
- this.add(panel2);
- }
- public void paint(Graphics g) {
- super.paint(g);
- Graphics2D g2 = (Graphics2D) g;
- Color Background = new Color(255, 110, 0);
- g2.setColor(Background);
- g2.fillRect(0, 0, 300, 650);
- Color border = new Color(225, 210, 0);
- g2.setColor(border);
- g2.fillRect(5, 102, 188, 164);
- g2.fillRect(5, 362, 188, 164);
- g2.setColor(Color.BLACK);
- g2.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 30));
- g2.drawString("MENU:", 20, 50);
- }
- @Override
- public void actionPerformed(ActionEvent evt) {
- if (evt.getActionCommand().equals("play")) {
- playClicked = true;
- }
- if (evt.getActionCommand().equals("tutorial")) {
- tutorialClicked = true;
- }
- }
- public static boolean getPlayClicked() {
- return playClicked;
- }
- public static boolean getTutorialClicked() {
- return tutorialClicked;
- }
- }
- class LeftPanel extends JPanel {
- JLabel label1;
- ImageIcon image;
- LeftPanel() throws IOException {
- this.setLayout(null);
- this.setBounds(0, 0, 800, 650);
- }
- public void paint(Graphics g) {
- super.paint(g);
- Graphics2D g2 = (Graphics2D) g;
- Color Border = new Color(225, 210, 0);
- g2.setColor(Border);
- g2.fillRect(0, 0, 800, 650);
- Color Background = new Color(255, 110, 0);
- g2.setColor(Background);
- g2.fillRect(10, 10, 770, 610);
- g2.setColor(Color.BLACK);
- g2.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 50));
- g2.drawString("HOW TO PLAY", 50, 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement