zopiac

Prog

Nov 3rd, 2010
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.98 KB | None | 0 0
  1. package butka;
  2. import java.awt.BorderLayout;
  3. import java.awt.Container;
  4. import java.awt.FlowLayout;
  5. import java.awt.Graphics;
  6. import java.awt.GridLayout;
  7. import java.awt.Image;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ItemListener;
  11. import java.awt.event.ItemEvent;
  12.  
  13. import java.awt.*;
  14. import java.awt.event.*;
  15. import javax.swing.*;
  16.  
  17. import javax.swing.Icon;
  18. import javax.swing.ImageIcon;
  19. import javax.swing.JButton;
  20. import javax.swing.JFrame;
  21. import javax.swing.JLabel;
  22. import javax.swing.JOptionPane;
  23. import javax.swing.JPanel;
  24. import javax.swing.JRadioButton;
  25. import javax.swing.JTextField;
  26. import javax.swing.JCheckBox;
  27. import javax.swing.text.*;
  28. import javax.swing.ButtonGroup;
  29. public class CharTraits extends JFrame implements ActionListener {
  30.     private GridLayout advsSectionLayout;
  31.     private GridLayout disadvsSectionLayout;
  32.     private ButtonGroup raceRGroup;
  33.     private JPanel nameRaceJPanel;
  34.     private JPanel advJPanel;
  35.     private JPanel disadvJPanel;
  36.     private JPanel traitsJPanel;
  37.     private JPanel infoJPanel;
  38.     private JPanel graphicJPanel;
  39.     private JCheckBox advantages[];
  40.     private JCheckBox disadvantages[];
  41.     private JRadioButton races[];
  42.     private String name;
  43.     private String race;
  44.     private Icon pcGraphic;
  45.     private JButton pcGraphicButton;
  46.     private int expNeed = 100;
  47.     private final String disadvNames[] = {"PlaceHolder (%1)", "PlaceHolder (%2)", "PlaceHolder (%3)",
  48.             "PlaceHolder (%4)", "PlaceHolder (%5)"};
  49.     private final String advNames[] = {"Toughness (%10)", "Woodsman (%6)", "Magically Apt. (%20)",
  50.             "Good Constitution (%10)", "Ambidextrous (%8)", "Highly Alert (%7)", "Nimble Fingers (%10)",
  51.             "Exceptional Strength (%12)", "Cave Lore (%4)", "Recuperation (%15)"};
  52.     private final String raceNames[] = {"Human (%0)", "Nephil (%12)", "Slithzerikai (%20)"};
  53.  
  54.  
  55.     //      private Icon human1L = new ImageIcon(getClass().getResource("C:/Human1Left.png"));
  56.     private Icon human1R = new ImageIcon("C:/Human1Right.png");
  57.     //  private Icon nephil1L = new ImageIcon(getClass().getResource("C:/Nephil1LeftA.png"));
  58.     private Icon nephil1R = new ImageIcon("C:/Nephil1RightA.png");
  59.     //  private Icon slith4L = new ImageIcon(getClass().getResource("C:/Slith4LeftA.png"));
  60.     private Icon slith4R = new ImageIcon("C:/Slith4RightA.png");
  61.     private JButton human1Button;
  62.     private JButton nephil1Button;
  63.     private JButton slith4Button;
  64.    
  65.     public CharTraits() {
  66.         super("Pick Stats");
  67.  
  68.         ///////////////////////////SELECT NAME/RACE---NAME/RACE
  69.  
  70.         JLabel nameLabel = new JLabel("Name:");
  71.         JTextField nameField = new JTextField("", 10);
  72.         JLabel raceLabel = new JLabel("         Race:");
  73.         raceRGroup = new ButtonGroup();
  74.         nameRaceJPanel = new JPanel();
  75.         nameRaceJPanel.add(nameLabel);
  76.         nameRaceJPanel.add(nameField);
  77.         nameRaceJPanel.add(raceLabel);
  78.         races = new JRadioButton[raceNames.length];
  79.         for (int count = 0; count < raceNames.length; ++count) {
  80.             races[count] = new JRadioButton(raceNames[count]);
  81.             races[count].addActionListener(this);
  82.             nameRaceJPanel.add(races[count]);
  83.             raceRGroup.add(races[count]);
  84.         }
  85.        
  86.         //////////////////////////SELECT ADVANTAGES--ADVANTAGES
  87.         JLabel advLabel = new JLabel("Advantages:");
  88.         advsSectionLayout = new GridLayout(5, 2, 2, 8);
  89.         advJPanel = new JPanel();
  90.         advJPanel.setLayout(advsSectionLayout);
  91.         advantages = new JCheckBox[advNames.length];
  92.         for (int count = 0; count < advNames.length; ++count) {
  93.             advantages[count] = new JCheckBox(advNames[count]);
  94.             advantages[count].addActionListener(this);
  95.             advJPanel.add(advantages[count]);
  96.         }
  97.         ////////////////////SELECT DISADVANTAGES--DISADVANTAGES
  98.         JLabel disadvLabel = new JLabel("Disadvantages:");
  99.         disadvsSectionLayout = new GridLayout(5, 1, 0, 8);
  100.         disadvJPanel = new JPanel();
  101.         disadvJPanel.setLayout(disadvsSectionLayout);
  102.         disadvantages = new JCheckBox[disadvNames.length];
  103.         for (int count = 0; count < disadvNames.length; ++count) {
  104.             disadvantages[count] = new JCheckBox(disadvNames[count]);
  105.             disadvantages[count].addActionListener(this);
  106.             disadvJPanel.add(disadvantages[count]);
  107.         }
  108.         ///////////////////////////////SELECT GRAPHIC---GRAPHIC
  109.         JLabel graphicLabel = new JLabel("Graphic:");
  110.         graphicJPanel = new JPanel();
  111.         graphicJPanel.setLayout(new GridLayout(2, 1, 2, 2));
  112.         human1Button = new JButton(/*"Human 1",*/ human1R);
  113.         nephil1Button = new JButton(/*"Nephilim 1",*/ nephil1R);
  114.         slith4Button = new JButton(/*"Slithzerikai 4",*/ slith4R);
  115.         graphicJPanel.add(human1Button);
  116.         graphicJPanel.add(nephil1Button);
  117.         graphicJPanel.add(slith4Button);
  118.         ButtonHandler handler = new ButtonHandler();
  119.         human1Button.addActionListener(handler);
  120.         nephil1Button.addActionListener(handler);
  121.         slith4Button.addActionListener(handler);
  122.         human1Button.setActionCommand("Human1Right");
  123.         nephil1Button.setActionCommand("Nephil1RightA");
  124.         slith4Button.setActionCommand("Slith4RightA");
  125.        
  126.         /////SHOW CHARACTER INFORMATION---CHARACTER INFORMATION
  127.         name = "FillerName";
  128.         infoJPanel = new JPanel();
  129.         pcGraphicButton = new JButton(human1R);//pcGraphic);
  130. //      JLabel picture = new JLabel(createImageIcon("C:\\Human1Right.png"));
  131. //      infoJPanel.add(pcGraphic);
  132.         infoJPanel.add(pcGraphicButton);
  133.        
  134.         JLabel nameDisplay = new JLabel(name + " is " + race + " and needs " + expNeed + " experience per level.");
  135.         infoJPanel.add(nameDisplay);
  136.        
  137.         ///////////////////////SET SIZE/LOCATON---SIZE/LOCATION
  138.         nameRaceJPanel.setSize(600, 40);
  139.         nameRaceJPanel.setLocation(0, 0);
  140.         advLabel.setSize(70, 30);
  141.         advLabel.setLocation(40, 50);
  142.         advJPanel.setSize(400, 120);
  143.         advJPanel.setLocation(50, 80);
  144.         disadvLabel.setSize(90, 30);
  145.         disadvLabel.setLocation(40, 200);
  146.         disadvJPanel.setSize(125, 120);
  147.         disadvJPanel.setLocation(50, 240);
  148.         graphicLabel.setSize(50, 30);
  149.         graphicLabel.setLocation(200, 200);
  150.         graphicJPanel.setSize(70, 90);
  151.         graphicJPanel.setLocation(200, 240);
  152.         infoJPanel.setSize(600, 60);
  153.         infoJPanel.setLocation(0, 400);
  154.        
  155.         ///////////////////ADD TO traitsJPanel/ADD traitsJPanel
  156.         traitsJPanel = new JPanel();
  157.         traitsJPanel.setLayout(null);
  158.         traitsJPanel.add(nameRaceJPanel);
  159.         traitsJPanel.add(advLabel);
  160.         traitsJPanel.add(advJPanel);
  161.         traitsJPanel.add(disadvLabel);
  162.         traitsJPanel.add(disadvJPanel);
  163.         traitsJPanel.add(graphicLabel);
  164.         traitsJPanel.add(graphicJPanel);
  165.         traitsJPanel.add(infoJPanel);
  166.         add(traitsJPanel);
  167.     }
  168.     public void actionPerformed(ActionEvent e) {
  169. //        pcGraphicButton.setImage("images/" + e.getActionCommand() + ".gif");
  170.     }
  171.     private class ButtonHandler implements ActionListener {
  172.         public void actionPerformed( ActionEvent event ) {
  173.             if (event.getActionCommand() == "Human") {
  174.                 pcGraphic = human1R;
  175.                 race = "Human";
  176.             } else if (event.getActionCommand() == "Nephilim") {
  177.                 pcGraphic = nephil1R;
  178.                 race = "Nephilim";
  179.             } else if (event.getActionCommand() == "Slithzerikai") {
  180.                 pcGraphic = slith4R;
  181.                 race = "Slithzerikai";
  182.             }
  183.             JOptionPane.showMessageDialog(CharTraits.this, (race));
  184.         }
  185.     }
  186. }
Add Comment
Please, Sign In to add comment