Subscribe to jtcoder522's Blog        RSS Feed
-----

codev4

Icon Leave Comment



//Judson Frampton
//Java final project 
// Snake
//4-4-2014
import javax.swing.*;
import javax.swing.Box.Filler;

import java.awt.*;
import java.awt.event.*;

public class SnakeObject extends JFrame
{
	public SnakeObject()
	{
		createframe();
	}
// method to create the frame of the game
		public void createframe()
		{
			ButtonEventHandler eventHandler;
			eventHandler = new ButtonEventHandler();
			JFrame snakeFrame = new JFrame();
			setTitle("Snake");
			setSize(350, 400);
			setVisible(true);
			 JButton Playb;
			Playb = new JButton("Play!");
			Playb.setBackground(Color.black);
			Playb.setForeground(Color.red);
			Playb.addActionListener(eventHandler);
			Playb.setAlignmentX(Component.CENTER_ALIGNMENT);
			JButton Instructionsb;
			JButton Creditsb;
			JLabel Lsnake=new JLabel("Snake",JLabel.CENTER);
			Lsnake.setFont(new Font("Serif", Font.BOLD, 40));
			Lsnake.setForeground(Color.red);
			Instructionsb = new JButton("Instructions!");
			Instructionsb.setAlignmentX(Component.CENTER_ALIGNMENT);
			Creditsb = new JButton("Credits!");
			Creditsb.setAlignmentX(Component.CENTER_ALIGNMENT);
			JPanel Labelpanel = new JPanel();
			Labelpanel.setBackground(Color.GRAY);
			Labelpanel.add(Lsnake);
			JPanel panel= new JPanel();
			panel.setBackground(Color.GRAY);
			panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
			panel.setBorder(BorderFactory.createEmptyBorder(100, 0, 0, 0));
			panel.add(Playb,JButton.CENTER_ALIGNMENT);
			panel.add(Box.createRigidArea(new Dimension(0, 10)));
			panel.add(Instructionsb,JButton.CENTER_ALIGNMENT);
			panel.add(Box.createRigidArea(new Dimension(0, 10)));
			panel.add(Creditsb,JButton.CENTER_ALIGNMENT);
			Container pane= getContentPane();
			pane.setLayout(new BorderLayout());
			pane.add(Labelpanel,BorderLayout.PAGE_START);
			pane.add(panel);
			
			
		}
			public class ButtonEventHandler implements ActionListener
			{
				public void actionPerformed(ActionEvent e)
				{
					String str =e.getActionCommand();
					if (str.equals("Play!"))
					{
						dispose();
						new creategameframe();
					}
				}
			}
}
		class creategameframe extends JFrame
		{	
			public creategameframe ()
				{
			JFrame gameFrame= new JFrame();
			gameFrame.setTitle("Snake Game");
			gameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			gameFrame.add(new snake());
			gameFrame.pack();
			gameFrame.setVisible(true);
				}
		
		}
		
		 class snake extends JPanel
		{
			 
			public snake()
			{
				
				setBorder(BorderFactory.createLineBorder(Color.black));
				setBackground(Color.red);
				 
			}
			 public Dimension getPreferredSize() 
			 	{
			        return new Dimension(500,500);
			    }
			 void PaintComponent(Graphics g)
			{   
				super.paintComponent(g);
				g.drawString("hi", 50, 50);
				 	g.setColor(Color.green);
			        g.fillRect(10,10,100,100);
			        g.setColor(Color.BLACK);
			        g.drawRect(10,10,100,100);
			}
		 }
	
	

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

November 2014

S M T W T F S
      1
2345678
9101112131415
16171819202122
2324252627 28 29
30      

Tags

    Recent Entries

    • codev4

      on Apr 25 2014 10:25 AM

    • Icon  code v3

      on Apr 11 2014 10:25 AM

    • Icon  code

      on Apr 10 2014 09:57 AM

    • Icon  code

      on Apr 08 2014 10:28 AM

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories