Advertisement
Guest User

Java Help

a guest
Jan 19th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.59 KB | None | 0 0
  1. import java.awt.GridLayout;
  2. import java.awt.Graphics;
  3. import java.awt.event.KeyAdapter;
  4. import java.awt.event.KeyEvent;
  5. import java.awt.event.WindowAdapter;
  6. import java.awt.event.WindowEvent;
  7. import javax.swing.JLabel;
  8. import javax.swing.JPanel;
  9. import javax.swing.JFrame;
  10. import javax.swing.ImageIcon;
  11. import java.awt.*;
  12. import javax.swing.*;
  13. import java.awt.Color;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.image.BufferedImage;
  17. import java.io.*;
  18. import javax.imageio.ImageIO;
  19. import java.util.Random;
  20.  
  21. public class Board implements ActionListener{
  22.  
  23.  
  24.   private JButton draw, roll, done;    
  25.   private Container background, buttonst, buttonsl, buttonsr, buttonsb;
  26.   private JButton a, b, c, d , e, f, g, h, i, j, k, l;
  27.   private JButton m, n, o, p, q, r;
  28.   private JButton s, t, u, v ,w ,x;
  29.     private JButton y, z, aa, ab, ac, ad, ae, af, ag, ah, ai, aj,Roll,DrawCard;
  30.     private JLabel P1,P2,P3,P4,testes;
  31.     private JPanel totalGUI, buttonsTop, buttonsLeft, buttonsRight, buttonsBottom, MainButt, PlayerInfo;
  32.     private ImageIcon icon, test, test1;
  33.     private Character player1,player2,player3,player4;
  34.     private int coordx1,coordy1;
  35.     private JLayeredPane layeredPane;
  36.  
  37.  
  38.   public JPanel createContentPane (){
  39.     JPanel totalGUI = new JPanel();
  40.     totalGUI.setOpaque(false);
  41.     totalGUI.setLayout(null);
  42.     totalGUI.setVisible(false);
  43.     ImageIcon test1 = new ImageIcon(getClass().getResource("buffguychar.png"));
  44.     ImageIcon test = new ImageIcon(getClass().getResource("upgradebuildingcard.png"));
  45.  
  46.    
  47.     player1 = new Character(300, 300);
  48.     player2 = new Character();
  49.     player3 = new Character();
  50.     player4 = new Character();
  51.  
  52.  
  53.    
  54.     PlayerInfo = new JPanel();
  55.     PlayerInfo.setLayout(null);
  56.     PlayerInfo.setLocation(100,100);
  57.     PlayerInfo.setSize(1000,600);
  58.     PlayerInfo.setOpaque(false);
  59.     PlayerInfo.add(player1);
  60.     totalGUI.add(PlayerInfo);
  61.     totalGUI.add(player1);
  62.    
  63.  
  64.    
  65.     MainButt = new JPanel();
  66.     MainButt.setLocation(500,500);
  67.     MainButt.setSize(100,100);
  68.     totalGUI.add(MainButt);
  69.    
  70.     buttonsTop = new JPanel();
  71.     buttonsTop.setLayout(null);
  72.     buttonsTop.setLocation(0, 0);
  73.     buttonsTop.setSize(1200, 100);
  74.     buttonsTop.setOpaque(false);
  75.     totalGUI.add(buttonsTop);
  76.    
  77.    
  78.     buttonsLeft = new JPanel();
  79.     buttonsLeft.setLayout(null);
  80.     buttonsLeft.setLocation(0, 100);
  81.     buttonsLeft.setSize(100, 600);
  82.     buttonsLeft.setOpaque(false);
  83.     totalGUI.add(buttonsLeft);
  84.    
  85.     buttonsRight = new JPanel();
  86.     buttonsRight.setLayout(null);
  87.     buttonsRight.setLocation(1100, 100);
  88.     buttonsRight.setSize(100, 600);
  89.     buttonsRight.setOpaque(false);
  90.     totalGUI.add(buttonsRight);
  91.    
  92.     buttonsBottom = new JPanel();
  93.     buttonsBottom.setLayout(null);
  94.     buttonsBottom.setLocation(0, 700);
  95.     buttonsBottom.setSize(1200, 100);
  96.     buttonsBottom.setOpaque(false);
  97.     totalGUI.add(buttonsBottom);
  98.    
  99.     a = new JButton(test);
  100.     a.setIcon(test);
  101.     a.setLocation(0, 0);
  102.     a.setSize(100, 100);
  103.     a.addActionListener(this);
  104.     buttonsTop.add(a);
  105.    
  106.    
  107.     b = new JButton(test);
  108.     b.setIcon(test1);
  109.     b.setText("hI");
  110.     b.setLocation(100, 0);
  111.     b.setSize(100, 100);
  112.     b.addActionListener(this);
  113.     buttonsTop.add(b);
  114.    
  115.     c = new JButton(test1);
  116.     c.setLocation(200, 0);
  117.     c.setSize(100, 100);
  118.     c.addActionListener(this);
  119.     buttonsTop.add(c);
  120.    
  121.     d = new JButton(test);
  122.     d.setLocation(300, 0);
  123.     d.setSize(100, 100);
  124.     d.addActionListener(this);
  125.     buttonsTop.add(d);
  126.    
  127.     e = new JButton(test);
  128.     e.setLocation(400, 0);
  129.     e.setSize(100, 100);
  130.     e.addActionListener(this);
  131.     buttonsTop.add(e);
  132.    
  133.     f = new JButton(test);
  134.     f.setLocation(500, 0);
  135.     f.setSize(100, 100);
  136.     f.addActionListener(this);
  137.     buttonsTop.add(f);
  138.    
  139.     g = new JButton(test);
  140.     g.setLocation(600, 0);
  141.     g.setSize(100, 100);
  142.     g.addActionListener(this);
  143.     buttonsTop.add(g);
  144.    
  145.     h = new JButton(test);
  146.     h.setLocation(700, 0);
  147.     h.setSize(100, 100);
  148.     h.addActionListener(this);
  149.     buttonsTop.add(h);
  150.    
  151.     i = new JButton(test);
  152.     i.setLocation(800, 0);
  153.     i.setSize(100, 100);
  154.     i.addActionListener(this);
  155.     buttonsTop.add(i);
  156.    
  157.     j = new JButton(test);
  158.     j.setLocation(900, 0);
  159.     j.setSize(100, 100);
  160.     j.addActionListener(this);
  161.     buttonsTop.add(j);
  162.    
  163.     k = new JButton(test);
  164.     k.setLocation(1000, 0);
  165.     k.setSize(100, 100);
  166.     k.addActionListener(this);
  167.     buttonsTop.add(k);
  168.    
  169.     l = new JButton(test);
  170.     l.setLocation(1100, 0);
  171.     l.setSize(100, 100);
  172.     l.addActionListener(this);
  173.     buttonsTop.add(l);
  174.    
  175.    
  176.    
  177.     m = new JButton(test);
  178.     m.setLocation(0, 0);
  179.     m.setSize(100, 100);
  180.     m.addActionListener(this);
  181.     buttonsLeft.add(m);
  182.    
  183.     n = new JButton(test);
  184.     n.setLocation(0, 100);
  185.     n.setSize(100, 100);
  186.     n.addActionListener(this);
  187.     buttonsLeft.add(n);
  188.    
  189.     o = new JButton(test);
  190.     o.setLocation(0, 200);
  191.     o.setSize(100, 100);
  192.     o.addActionListener(this);
  193.     buttonsLeft.add(o);
  194.    
  195.     p = new JButton(test);
  196.     p.setLocation(0, 300);
  197.     p.setSize(100, 100);
  198.     p.addActionListener(this);
  199.     buttonsLeft.add(p);
  200.    
  201.     q = new JButton(test);
  202.     q.setLocation(0, 400);
  203.     q.setSize(100, 100);
  204.     q.addActionListener(this);
  205.     buttonsLeft.add(q);
  206.    
  207.     r = new JButton(test);
  208.     r.setLocation(0, 500);
  209.     r.setSize(100, 100);
  210.     r.addActionListener(this);
  211.     buttonsLeft.add(r);
  212.    
  213.    
  214.    
  215.     s = new JButton(test);
  216.     s.setLocation(0, 0);
  217.     s.setSize(100, 100);
  218.     s.addActionListener(this);
  219.     buttonsRight.add(s);
  220.    
  221.     t = new JButton(test);
  222.     t.setLocation(0, 100);
  223.     t.setSize(100, 100);
  224.     t.addActionListener(this);
  225.     buttonsRight.add(t);
  226.    
  227.     u = new JButton(test);
  228.     u.setLocation(0, 200);
  229.     u.setSize(100, 100);
  230.     u.addActionListener(this);
  231.     buttonsRight.add(u);
  232.    
  233.     v = new JButton(test);
  234.     v.setLocation(0, 300);
  235.     v.setSize(100, 100);
  236.     v.addActionListener(this);
  237.     buttonsRight.add(v);
  238.    
  239.     w = new JButton(test);
  240.     w.setLocation(0, 400);
  241.     w.setSize(100, 100);
  242.     w.addActionListener(this);
  243.     buttonsRight.add(w);
  244.    
  245.     x = new JButton(test);
  246.     x.setLocation(0, 500);
  247.     x.setSize(100, 100);
  248.     x.addActionListener(this);
  249.     buttonsRight.add(x);
  250.    
  251.    
  252.    
  253.     y = new JButton(test);
  254.     y.setLocation(0, 0);
  255.     y.setSize(100, 100);
  256.     y.addActionListener(this);
  257.     buttonsBottom.add(y);
  258.    
  259.     z = new JButton(test);
  260.     z.setLocation(100, 0);
  261.     z.setSize(100, 100);
  262.     z.addActionListener(this);
  263.     buttonsBottom.add(z);
  264.    
  265.     aa = new JButton(test);
  266.     aa.setLocation(200, 0);
  267.     aa.setSize(100, 100);
  268.     aa.addActionListener(this);
  269.     buttonsBottom.add(aa);
  270.    
  271.     ab = new JButton(test);
  272.     ab.setIcon(test);
  273.     ab.setLocation(300, 0);
  274.     ab.setSize(100, 100);
  275.     ab.addActionListener(this);
  276.     buttonsBottom.add(ab);
  277.    
  278.     ac = new JButton(test);
  279.     ac.setLocation(400, 0);
  280.     ac.setSize(100, 100);
  281.     ac.addActionListener(this);
  282.     buttonsBottom.add(ac);
  283.    
  284.     ad = new JButton(test);
  285.     ad.setLocation(500, 0);
  286.     ad.setSize(100, 100);
  287.     ad.addActionListener(this);
  288.     buttonsBottom.add(ad);
  289.    
  290.     ae = new JButton(test);
  291.     ae.setLocation(600, 0);
  292.     ae.setSize(100, 100);
  293.     ae.addActionListener(this);
  294.     buttonsBottom.add(ae);
  295.    
  296.     af = new JButton(test);
  297.     af.setLocation(700, 0);
  298.     af.setSize(100, 100);
  299.     af.addActionListener(this);
  300.     buttonsBottom.add(af);
  301.    
  302.     ag = new JButton(test);
  303.     ag.setLocation(800, 0);
  304.     ag.setSize(100, 100);
  305.     ag.addActionListener(this);
  306.     buttonsBottom.add(ag);
  307.    
  308.    
  309.     ah = new JButton(test);
  310.     ah.setLocation(900, 0);
  311.     ah.setSize(100, 100);
  312.     ah.addActionListener(this);
  313.     buttonsBottom.add(ah);
  314.    
  315.     ai = new JButton(test);
  316.     ai.setLocation(1000, 0);
  317.     ai.setSize(100, 100);
  318.     ai.addActionListener(this);
  319.     buttonsBottom.add(ai);
  320.    
  321.     aj = new JButton("Start");
  322.     aj.setLocation(1100, 0);
  323.     aj.setSize(100, 100);
  324.     aj.addActionListener(this);
  325.     buttonsBottom.add(aj);
  326.    
  327.    
  328.     DrawCard = new JButton("Draw");
  329.     DrawCard.setSize(200,120);
  330.     DrawCard.setLocation(400,200);
  331.     DrawCard.addActionListener(new ActionListener() {
  332.      public void actionPerformed(ActionEvent e){
  333.   Commands.Roll();
  334.      }
  335.  });
  336.     PlayerInfo.add(DrawCard);
  337.  
  338.     Roll = new JButton("Roll");
  339.     Roll.setLocation(460,400);
  340.     Roll.setSize(75,75);
  341.     Roll.addActionListener(new ActionListener() {
  342.       public void actionPerformed(ActionEvent e)
  343.       {Commands.Roll();
  344.       }
  345.     });
  346.     PlayerInfo.add(Roll);
  347.  
  348.    
  349.     P1 = new JLabel("P1 Money:" + player1.getMoney());
  350.     P1.setSize(200,100);
  351.     P1.setLocation(0,0);
  352.     PlayerInfo.add(P1);
  353.    
  354.     P2 = new JLabel("P2 Money:" + player2.getMoney());
  355.     P2.setSize(200,100);
  356.     P2.setLocation(800,0);
  357.     PlayerInfo.add(P2);
  358.    
  359.     P3 = new JLabel("P3 Money:" + player3.getMoney());
  360.     P3.setSize(200,100);
  361.     P3.setLocation(0,500);
  362.     PlayerInfo.add(P3);
  363.    
  364.     P4 = new JLabel("P4 Money:" + player4.getMoney());
  365.     P4.setSize(200,100);
  366.     P4.setLocation(800,500);
  367.     PlayerInfo.add(P4);
  368.    
  369.    
  370.    
  371.    
  372.    
  373.     /* buttonst = new Container();
  374.      buttonst.setLayout(new GridLayout(1,12));
  375.      buttonst.add(a);
  376.      buttonst.add(b);
  377.      buttonst.add(c);
  378.      buttonst.add(d);
  379.      buttonst.add(e);
  380.      buttonst.add(f);
  381.      buttonst.add(g);
  382.      buttonst.add(h);
  383.      buttonst.add(i);
  384.      buttonst.add(j);
  385.      buttonst.add(k);
  386.      buttonst.add(l);
  387.      
  388.      
  389.      buttonsl = new Container();
  390.      buttonsl.setLayout(new GridLayout(6, 1));
  391.      buttonsl.add(m);
  392.      buttonsl.add(n);
  393.      buttonsl.add(o);
  394.      buttonsl.add(p);
  395.      buttonsl.add(q);
  396.      buttonsl.add(r);
  397.      
  398.      buttonsr = new Container();
  399.      buttonsr.setLayout(new GridLayout(6, 1));
  400.      buttonsr.add(s);
  401.      buttonsr.add(t);
  402.      buttonsr.add(u);
  403.      buttonsr.add(v);
  404.      buttonsr.add(w);
  405.      buttonsr.add(x);
  406.      
  407.      buttonsb = new Container();
  408.      buttonsb.setLayout(new GridLayout(1, 12));
  409.      buttonsb.add(y);
  410.      buttonsb.add(z);
  411.      buttonsb.add(aa);
  412.      buttonsb.add(ab);
  413.      buttonsb.add(ac);
  414.      buttonsb.add(ad);
  415.      buttonsb.add(ae);
  416.      buttonsb.add(af);
  417.      buttonsb.add(ag);
  418.      buttonsb.add(ah);
  419.      buttonsb.add(ai);
  420.      buttonsb.add(aj); */
  421.    
  422.    
  423.     /* buttonsTop.add(buttonst);
  424.      buttonsLeft.add(buttonsl);
  425.      buttonsRight.add(buttonsr);
  426.      buttonsBottom.add(buttonsb);
  427.      */
  428.    
  429.     totalGUI.setOpaque(false);
  430.     return totalGUI;
  431.  
  432.   }
  433.  
  434.   private static void createAndShowGUI() {
  435.    
  436.     JFrame.setDefaultLookAndFeelDecorated(true);
  437.     JFrame frame = new JFrame("Thugopoly");
  438.     //Create and set up the content pane.
  439.     Board demo = new Board();
  440.     Character s = new Character(400,400);
  441.     frame.add(s);
  442.     frame.setContentPane(demo.createContentPane());
  443.     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  444.     frame.setSize(1210, 830);
  445.     frame.setVisible(true);
  446.     frame.setResizable(false);
  447.    
  448.    
  449.    
  450.   }
  451.  
  452.   public void actionPerformed(ActionEvent e) {
  453.     int x = 1;
  454.     if(e.getSource() == a){
  455.       x = 1;
  456.     }
  457.   }
  458.  
  459.  
  460.   public static void main(String[] args) {
  461.     //Schedule a job for the event-dispatching thread:
  462.     //creating and showing this application's GUI.
  463.     SwingUtilities.invokeLater(new Runnable() {
  464.       public void run() {
  465.         createAndShowGUI();
  466.       }
  467.     }
  468.     );
  469.   }
  470. }
  471.  
  472.  
  473.  
  474. import javax.swing.*;
  475. import java.awt.*;
  476. import java.awt.event.*;
  477. public class Character extends JPanel{
  478.    
  479.     private String name;
  480.     private int x ,y, money;
  481.     private ImageIcon image;
  482.  
  483.  
  484.     public void paintComponent(Graphics g){
  485.       super.paintComponent(g);
  486.       ImageIcon image = new ImageIcon(getClass().getResource("buffguychar.png"));
  487.       image.paintIcon(this, g, x, y);
  488.       validate();
  489.     }
  490.  
  491.     public Character(int a, int b ){
  492.  x = a;
  493.  y = b;
  494.  name = "tester";
  495.  money = 1000;
  496.      }
  497.  
  498.     public Character(){
  499.  x = 1200;
  500.  y = 800;
  501.  money = 1000;
  502.  
  503.     }
  504.  
  505.     public void addMoney(int a){
  506.  money += a;
  507.     }
  508.  
  509.     public int getMoney(){
  510.  return money;
  511.     }
  512.  
  513.     public int getx(){
  514.  return x;
  515.     }
  516.  
  517.     public int gety(){
  518.  return y;
  519.     }
  520.  
  521.     public void setx(int n){
  522.  x = n;
  523.     }
  524.    
  525.     public void sety(int n){
  526.  y = n;
  527.     }
  528. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement