Jcombobox,JButton problem

Hi,
i would like my button to show a new java class,
My button actionlistener
select2 select = new select2();
select.createAndShowGUI();but, i want to choose which class i will go through JComboBox.....
Let's say my string on the JComboBox is frame1,frame2,frame3....
how should i put it in way that....
if frame1 is selected....
i click the button, it will show frame1 class...
if frame2 is selcted....
after clicked the button, it will show frame2 class...
Edited by: vanharu on May 27, 2008 8:38 PM

i understand the codes u put there...
but how do i implement it to my button action
* @(#)select2.java
* @author
* @version 1.00 2008/5/28
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.BoxLayout;
public class select2 extends JFrame  implements ActionListener
     public JComboBox CharList;
     public JLabel Char,title;
     public JButton Play, Preview;
    public select2()
        setTitle("Select Your Character");
        setSize(340, 400);
        getContentPane().setLayout(
                new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
         Border raisedbevel, loweredbevel, compound;
         raisedbevel = BorderFactory.createRaisedBevelBorder();
        loweredbevel = BorderFactory.createLoweredBevelBorder();
          // Puts in array of strings to the combo box
        // Can select the arrays that is inserted in the combo box
            String hero[] = {"Naruto", "Sasuke", "Ichigo", "Ulqiourra"};
            CharList = new JComboBox(hero);
         //Shows that the combo box will start at 0,
         //which is naruto  
            CharList.setSelectedIndex(0);
            CharList.addActionListener(this);
             //Set up the animation part
                Char = new JLabel();
              Char.setHorizontalAlignment(JLabel.CENTER);
              updateLabel(hero[CharList.getSelectedIndex()]);
              compound = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel);
              Char.setBorder(compound);
              Char.setPreferredSize(new Dimension(320, 266));
              //Set up button part
              Play = new JButton("Select This Character");
             Play.setHorizontalAlignment(4);
             Play.setPreferredSize(new Dimension(100,40));
             Play.addActionListener(new confirm());
                  Preview = new JButton("Preview This Character");
                  Preview.setHorizontalAlignment(4);
                  Preview.setPreferredSize(new Dimension(80, 40));
                  Preview.addActionListener(new preview());     
                  getContentPane().add(CharList);
             CharList.setAlignmentX(Component.CENTER_ALIGNMENT);
             getContentPane().add(Char);
             Char.setAlignmentX(Component.CENTER_ALIGNMENT);
             getContentPane().add(Play);
             Play.setAlignmentX(Component.CENTER_ALIGNMENT);
             getContentPane().add(Preview);
              Preview.setAlignmentX(Component.CENTER_ALIGNMENT);
    public void actionPerformed(ActionEvent e)
             JComboBox nm = (JComboBox)e.getSource();
             String CharName = (String)nm.getSelectedItem();
             updateLabel(CharName);
    class confirm implements ActionListener {
        public void actionPerformed(ActionEvent event)
           System.exit(0);
    class preview implements ActionListener {
        public void actionPerformed(ActionEvent event)
        //lets say, if the combobox selection is naruto...
        //then when i click this button
        //it will show naruto class
         should i put like something like
         combobox = naruto
         show naruto.class
     protected void updateLabel(String name) {
        ImageIcon icon = new ImageIcon("Resources/"+name+"Pose" + ".gif");
        Char.setIcon(icon);
        Char.setToolTipText(name);
        if (icon != null) {
            Char.setText(null);
        } else {
            Char.setText("UNDER CONSTRUCTION");
   public static void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        //Create and set up the window.
        JFrame frame = new JFrame("Choose Your Character");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
          //Display the window.
        select2 sel = new select2();
        sel.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        sel.setVisible(true);
     public static void main(String[] args) {
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}Edited by: vanharu on May 27, 2008 10:27 PM

Similar Messages

  • JComboBox Render Problem........

    Hi I have a problem in JCombox renderer in my application Problem is i have Three comboBox columns in my table wing same Renderer and Editor. second and third combo column's aree working fine But in first combo-column if i add a new row clicking add button and if change a value in top- most comboBox i will reflect in all ComboBox's below, this is not happening in othe two Combo-column. i'am not at all gettin why this happens where i am using same renderer for all combo-columns how to stop this, When a new row is add ComboBox first item as Selected,
    Can any one please tell me how to solve this,
    since i cannot past entair application i am pasting example with similar suituation using same renderer.
    Thank's in Advance
    CODE:-
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    * @author 501376972
    public class MainTable extends JFrame{
    DefaultTableModel model = null;
    JTable table = null;
    JScrollPane scrollpane = null;
    JButton btCancel = null;
    JButton btADD = null;
    JPanel panelButton = null;
    public Object[][] data = null;
    String column[] = {" ","A","B","C","D","E","F"};
    String oprator[] = {" ","=","/","*","-","+"};
    String number[] = {" ","1","2","3","4","5","6"};
    /** Creates a new instance of MainTable */
    public MainTable() {
    model = new DefaultTableModel();
    model.addColumn("Column");
    model.addColumn("Operator");
    model.addColumn("Value");
    model.addColumn("Number");
    table = new JTable();
    table.setModel(model);
    data = new Object[][]{
    {column, oprator, null, number}
    model.addRow(data);
    TableColumn colCol = table.getColumnModel().getColumn(0);
    colCol.setCellRenderer(new ComboBoxCellRenderer(column));
    colCol.setCellEditor(new ComboBoxCellEditor(column));
    TableColumn colOpr = table.getColumnModel().getColumn(1);
    colOpr.setCellRenderer(new ComboBoxCellRenderer(oprator));
    colOpr.setCellEditor(new ComboBoxCellEditor(oprator));
    TableColumn colLog = table.getColumnModel().getColumn(3);
    colLog.setCellRenderer(new ComboBoxCellRenderer(number));
    colLog.setCellEditor(new ComboBoxCellEditor(number));
    scrollpane = new JScrollPane(table);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(scrollpane,BorderLayout.CENTER);
    panelButton = new JPanel();
    btADD = new JButton("ADD");
    btCancel = new JButton("Cancel");
    panelButton.add(btADD);
    panelButton.add(btCancel);
    getContentPane().add(panelButton,BorderLayout.SOUTH);
    btCancel.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    dispose();
    btADD.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    model.addRow(data);
    getContentPane().add(scrollpane);
    setSize(500,500);
    class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer {
    public ComboBoxCellRenderer(String[] items) {
    super(items);
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected) {
    //DO NOTHIING
    } else {
    //DO NOTHIING
    // Select the current value
    if(value == null)
    setSelectedIndex(0);
    else
    setSelectedItem(value);
    return this;
    public class ComboBoxCellEditor extends DefaultCellEditor {
    public ComboBoxCellEditor(String[] items) {
    super(new JComboBox(items));
    * @param args the command line arguments
    public static void main(String[] args) {
    MainTable mt = new MainTable();
    mt.setVisible(true);
    }

    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.
    Don't know why the code works the way it does, but the code is wrong. The correct way to add a row is like this:
    //model.addRow(data);
    String[] rowData = { " ", " ", " ", " "};
    model.addRow(rowData);

  • JCombobox selection problem

    Hello,
    I have some problem implementing events associated with JComboBox. My requirement is "the event should get fired only when an item is selected in the combobox". It may occur thet using arrow keys I can traverse all elements in the combobox and on item change the event should not get fired. I tried with itemstatechanged, actionperformed but no result.
    Any help will be appreciated.
    regards,
    Ranjan

    A simple working example:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ComboBoxAction extends JFrame implements ActionListener
         private JComboBox comboBox;
         public ComboBoxAction()
              comboBox = new JComboBox();
              comboBox.addActionListener( this );
              comboBox.addItem( "Item 1" );
              comboBox.addItem( "Item 2" );
              comboBox.addItem( "Item 3" );
              comboBox.addItem( "Item 4" );
              //  This prevents action events from being fired when the
              //  up/down arrow keys are used on the dropdown menu
              comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
              getContentPane().add( comboBox );
         public void actionPerformed(ActionEvent e)
              System.out.println( comboBox.getSelectedItem() );
              //  make sure popup is closed when 'isTableCellEditor' is used
              comboBox.hidePopup();
         public static void main(String[] args)
              JFrame frame = new ComboBoxAction();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
    }

  • JcomboBox + FOR - problem

    Hi,
    I try changing this code:
    ArrayList<String> tmp = new ArrayList<String>();
    tmp.add(numbertext.getText());
    for(String temp1 : tmp)
    System.out.println("a="+temp1.toString());
    <b>
    Legend:
    </b>
    numbertext is a JtextField.for JComboBox using FOR but i have error and problems.
    String[] items = {"item1", "item2", "item3"};
    jComboBox1.setModel(new DefaultComboBoxModel(items));
    int num = jComboBox1.getItemCount();
    String my = Integer.toString(num);
    for (String s : my ) {
            Object item = jComboBox1.getItemAt(num);
            System.out.println("a="+s.toString());I don;t know how to translate for JComoboBox.
    Please help

    Hmmmm,
    I try creating code which I choose in JComoboBox1 value for example Items2 and I click the button. My first value Items2 will be include in string, next I choose value items 4 in JcomboBox and the second value will be in string. Now In string I have a 2 value: items 2 and items 4 And I will have doing choose new value to infinity.
    I don't now how to create.

  • JComboBox Strange Problem

    Hi,
    I am writting a program involving a JComboBox.
    My Question is:
    How can jComboBox1.getSelectedIndex() return 1 if the previous line was jComboBox1.setSelectedIndex(0).
    My code:
    File f=null;
    int at=0;
    boolean dontdoit=false;
        @SuppressWarnings("static-access")
    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
    System.out.println(jComboBox1.getSelectedIndex()+" "+dontdoit);
            if(jComboBox1.getSelectedIndex()==1 && at!=1 && !dontdoit) {
        at=1;
        JFileChooser jfc=new JFileChooser();
        int i=jfc.showOpenDialog(null);
        f=jfc.getSelectedFile();
    if(i==jfc.CANCEL_OPTION) {System.out.println("H");
        f=null;
        at=0;
        dontdoit=true;
        jComboBox1.setSelectedIndex(0);
        System.out.println(jComboBox1.getSelectedIndex());
        jComboBox1ItemStateChanged(null);
       return;
        try {
        SimpleAudioPlayer sap=new SimpleAudioPlayer(f.toURI().toURL().getPath());
        sap.audioPlayer.close();
        }catch(Exception e) {
            JOptionPane.showConfirmDialog(null,"This file is not a valid audio file.\nPlease select another.","Invalid",-1);
            jComboBox1ItemStateChanged(null);
    else {
        f=null;
        at=0;
    dontdoit=false;
    }I can't get it to work. Please Help

    Sorry:
    (Part 1)
    * Options.java
    * Created on May 19, 2009, 3:28 PM
    package chatx;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    * @author  Michael
    public class Options extends javax.swing.JFrame {
        /** Creates new form Options */
        public Options() {
            initComponents();
            if(!new File("C:\\ChatX\\Options\\RINGLEN.txt").exists()) {
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream("C:\\ChatX\\Options\\RINGLEN.txt");
                    fos.write("20".getBytes());
                    fos.close();
                } catch (Exception ex) {
            else {
                FileInputStream fos = null;
                try {
                    fos = new FileInputStream("C:\\ChatX\\Options\\RINGLEN.txt");
                    byte[] b = new byte[fos.available()];
                    fos.read(b);
                    jSpinner1.setValue(Integer.parseInt(new String(b)));
                    fos.close();
                } catch (Exception ex) {
                    Logger.getLogger(Options.class.getName()).log(Level.SEVERE, null, ex);
            if(new File("C:\\ChatX\\Options\\RINGTONE").exists()) {
                jComboBox1.setSelectedIndex(1);
                at=1;
        public void copyFile(File in, File out) throws Exception {
            FileInputStream fis  = new FileInputStream(in);
            FileOutputStream fos = new FileOutputStream(out);
            byte[] buf = new byte[1024];
            int i = 0;
            while((i=fis.read(buf))!=-1) {
                fos.write(buf, 0, i);
            fis.close();
            fos.close();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jPanel2 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jSpinner1 = new javax.swing.JSpinner();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jComboBox1 = new javax.swing.JComboBox();
            jLabel4 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Options", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
            jLabel1.setText("Ring Length:");
            jSpinner1.setValue(new Integer(20));
            jLabel2.setText("seconds");
            jLabel3.setText("Ring Tone:");
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Standard Ringing", "Custom" }));
            jComboBox1.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    jComboBox1ItemStateChanged(evt);
            jLabel4.setText("IP Address:");
            jTextField1.setEditable(false);
            jTextField1.setText("YOURIP");
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jTextField1)
                        .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSpinner1, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel2)
                    .addContainerGap(158, Short.MAX_VALUE))
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(155, Short.MAX_VALUE))
            );

  • JComboBox focus problem

    Hi all,
    I'm using a JComboBox, a JButton and a JTextArea added to a JPanel. What I doing is using the TextArea as a console, the JComboBox to enter commands in (and retrieve old ones) and the JButton to execute entered commands. This works fine except for one thing. After I have executed a command and output has been written to the textarea(console) I want the focus to shift back to the combobox so that the user simply can enter another command. Using requestFocus() the drop down menu part of the combobox receives the focus and not the textfield part.
    I have tried multiple ways of actually accessing the textfield component (combobox.getEditor().getEditorComponent().requestFocus()) to set the caret position to 0 but nothing seems to work.
    Any thoughts or ideas will be appreciated.
    Cheers,
    Marcus

    Try calling transferFocusBackword on your JButton instance. Hope this helps.

  • JComboBox listener problem

    Hi all,
    I have following problem, i use combobox and i need to write listener for selecting item.
    But both ActionListener and ItemListener are unusable for me, because i dont know how to differ between selecting item when combobox is poped up.
    I dont want to react on going thru items in popup, but only to FINAL select of button.
    Please Help.
    Mathew, HSIGP

         This works on non editable combo boxes
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ComboBoxAction extends JFrame implements ActionListener
         JComboBox comboBox;
         public ComboBoxAction()
              comboBox = new JComboBox();
              comboBox.addActionListener( this );
              comboBox.addItem( "Item 1" );
              comboBox.addItem( "Item 2" );
              comboBox.addItem( "Item 3" );
              comboBox.addItem( "Item 4" );
              //  This prevents action events from being fired when the
              //  up/down arrow keys are used on the dropdown menu
              comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
              getContentPane().add( comboBox );
         public void actionPerformed(ActionEvent e)
              System.out.println( comboBox.getSelectedItem() );
              //  make sure popup is closed when 'isTableCellEditor' is used
              comboBox.hidePopup();
         public static void main(String[] args)
              final ComboBoxAction frame = new ComboBoxAction();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
    }

  • JComboBox addActionListener problem?

    HI,
    i am using JComboBox to add each item action perform of use StyleEditorKit.FontSizeAction("String", int), but i only can add one item action perform only. See my code any problem...
    for(int i>12;i<=50 ; i++){
                  comboBox.addItem(" "+i);
               // i want to loop each item can function
                comboBox.addActionListener(new StyleEditorKit.FontSizeAcion("i ", i)Thanks

    FontSizeAction is able to set the size to a value delivered in String format as the command String of its ActionEvent. Unfortunately, the JComboBox doesn't deliver the String value of the selected item as command string but an arbitrary value to be set once. So you have to wrap your FontSizeAction in a custom ActionListener of your own where you retrieve the selected item, cast it to a String and pass this value to FontSizeAction as the command String of a new ActionEvent object.
    You should also get rid of that whitespace when creating the size value, String.valueOf(int) is a better way to create a String for an int.

  • JComboBox Visibility Problem

    Hi, I am trying to use JComboBox for selecting you race and gender in a RPG I am making, but The contents of the JComboBox will not appear in the small version (before you click the little arrow) unless you first move one of the JSliders... Could some one help me figure this out?
    //I call the class with this
         newGamePanel = new newGamePanel();
         newGamePanel.setLayout(null);
         newGamePanel.setBounds(0, 0, programWidth, programHeight);
         newGamePanel.setBackground(Color.black);
         frame.getContentPane().add(newGamePanel);
         newGamePanel.setVisible(true);
         newGamePanel.setUpAlpha();
         newGamePanel.repaint();
    //and here is my class where it all takes place...  The relivent method is setUpAlpha()
    public class newGamePanel extends JPanel//Sets up and grabs the information for the character creation
    implements ActionListener, ChangeListener
         JButton newGameOK;
         JTextField newGameName;
         JComboBox newGameRace, newGameGender;
         JSlider newGameSTR, newGameAGI, newGameVIT, newGameDEX, newGameINT, newGameLUK;
         JLabel nGameName, nGameRace, nGameGender, nGameSTR, nGameAGI, nGameVIT, nGameDEX, nGameINT, nGameLUK;
         int tempScrollA = 5, tempScrollB = 5, tempScrollC = 5, tempScrollD = 5, tempScrollE = 5, tempScrollF = 5;
         public void actionPerformed(ActionEvent e)//Action Performed Block
              if(e.getSource() == newGameOK)
                   gameState = "Story";
                   newGameGetInfo();
                   newGameStoryPanel.newGameStoryPanelInit();
         public void stateChanged(ChangeEvent e)//Scrollbar Listener Block
              if(e.getSource() == newGameSTR)
                   tempScrollA = 10 - (int)newGameSTR.getValue();
                   newGameINT.setValue(tempScrollA);
              if(e.getSource() == newGameINT)
                   tempScrollA = 10 - (int)newGameINT.getValue();
                   newGameSTR.setValue(tempScrollA);
              if(e.getSource() == newGameAGI)
                   tempScrollA = 10 - (int)newGameAGI.getValue();
                   newGameLUK.setValue(tempScrollA);
              if(e.getSource() == newGameLUK)
                   tempScrollA = 10 - (int)newGameLUK.getValue();
                   newGameAGI.setValue(tempScrollA);
              if(e.getSource() == newGameDEX)
                   tempScrollA = 10 - (int)newGameDEX.getValue();
                   newGameVIT.setValue(tempScrollA);
              if(e.getSource() == newGameVIT)
                   tempScrollA = 10 - (int)newGameVIT.getValue();
                   newGameDEX.setValue(tempScrollA);
              tempScrollA = (int)newGameSTR.getValue();
              tempScrollB = (int)newGameAGI.getValue();
              tempScrollC = (int)newGameVIT.getValue();
              tempScrollD = (int)newGameDEX.getValue();
              tempScrollE = (int)newGameINT.getValue();
              tempScrollF = (int)newGameLUK.getValue();
              nGameSTR.setText("Strength: " + tempScrollA);
              nGameAGI.setText("Agility: " + tempScrollB);
              nGameVIT.setText("Vitality: " + tempScrollC);
              nGameDEX.setText("Dexterity: " + tempScrollD);
              nGameINT.setText("Intelligence: " + tempScrollE);
              nGameLUK.setText("Luck: " + tempScrollF);
         public void setUpAlpha()//Huge block to set up Character creation screen
              int tempProgramLeft = (int)(programWidth /2) - 225;
              int tempProgramRight = (int)(programWidth /2) + 25;
              UIManager.put("Label.foreground", Color.white);
              nGameName = new JLabel("Character Name", JLabel.CENTER);
              nGameName.setBounds((int)((programWidth - 250) / 2), 35, 250, 20);
              nGameRace = new JLabel("Character Race", JLabel.CENTER);
              nGameRace.setBounds(tempProgramLeft, 135, 200, 20);
              nGameGender = new JLabel("Character Gender", JLabel.CENTER);
              nGameGender.setBounds(tempProgramRight, 135, 200, 20);
              nGameSTR = new JLabel("Strength: " + tempScrollA, JLabel.CENTER);
              nGameSTR.setBounds(tempProgramLeft, 230, 200, 20);
              nGameINT = new JLabel("Intelligence: " + tempScrollE, JLabel.CENTER);
              nGameINT.setBounds(tempProgramRight, 230, 200, 20);
              nGameVIT = new JLabel("Vitality: " + tempScrollB, JLabel.CENTER);
              nGameVIT.setBounds(tempProgramLeft, 300, 200, 20);
              nGameDEX = new JLabel("Dexterity: " + tempScrollD, JLabel.CENTER);
              nGameDEX.setBounds(tempProgramRight, 300, 200, 20);
              nGameAGI = new JLabel("Agility: " + tempScrollC, JLabel.CENTER);
              nGameAGI.setBounds(tempProgramRight, 370, 200, 20);
              nGameLUK = new JLabel("Luck: " + tempScrollF, JLabel.CENTER);
              nGameLUK.setBounds(tempProgramLeft, 370, 200, 20);
              newGameOK = new JButton("Start Game", null);
              newGameOK.setHorizontalTextPosition(AbstractButton.CENTER);
              newGameOK.setBackground(Color.black);
              newGameOK.setForeground(Color.white);
              newGameOK.setBounds((int)((programWidth - 100) / 2), 450, 100, 30);
              newGameOK.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.white));
              newGameName = new JTextField("Enter Name", 20);
              newGameName.setFont(new Font("Times New Roman", Font.BOLD, 12));
              newGameName.setForeground(Color.red);
              newGameName.setBackground(Color.black);
              newGameName.setBounds((int)((programWidth - 250) / 2), 60, 250, 25);
              newGameName.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.white));
         //     UIManager.put("ComboBox.foreground", Color.red);
         //     UIManager.put("ComboBox.background", Color.black);
         //     UIManager.put("ComboBox.border", BorderFactory.createMatteBorder(0, 0, 0, 7, Color.white));
              String[] newGameRaceAAA = {"Human", "Elf", "Dwarf"};
              newGameRace = new JComboBox(newGameRaceAAA);
              newGameRace.setSelectedIndex(0);
              newGameRace.setBounds(tempProgramLeft, 160, 200, 20);
              newGameRace.addActionListener(this);
              String[] newGameGenderAAA = {"Male", "Female"};
              newGameGender = new JComboBox(newGameGenderAAA);
              newGameGender.setSelectedIndex(0);
              newGameGender.setBounds(tempProgramRight, 160, 200, 20);
              newGameGender.addActionListener(this);
              UIManager.put("Slider.background", Color.black);
              newGameSTR = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameAGI = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameVIT = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameDEX = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameINT = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameLUK = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameSTR.setBounds(tempProgramLeft, 250, 200, 15);
              newGameINT.setBounds(tempProgramRight, 250, 200, 15);
              newGameVIT.setBounds(tempProgramLeft, 320, 200, 15);
              newGameDEX.setBounds(tempProgramRight, 320, 200, 15);
              newGameLUK.setBounds(tempProgramLeft, 390, 200, 15);
              newGameAGI.setBounds(tempProgramRight, 390, 200, 15);
              visiblePanelChecker();
              this.add(newGameOK);
              this.add(newGameName);
              this.add(newGameRace);
              this.add(newGameGender);
              this.add(newGameSTR);
              this.add(newGameAGI);
              this.add(newGameVIT);
              this.add(newGameDEX);
              this.add(newGameINT);
              this.add(newGameLUK);
              this.add(nGameName);
              this.add(nGameRace);
              this.add(nGameGender);
              this.add(nGameSTR);
              this.add(nGameAGI);
              this.add(nGameVIT);
              this.add(nGameDEX);
              this.add(nGameINT);
              this.add(nGameLUK);
              newGameOK.addActionListener(this);
              newGameSTR.addChangeListener(this);
              newGameAGI.addChangeListener(this);
              newGameVIT.addChangeListener(this);
              newGameDEX.addChangeListener(this);
              newGameINT.addChangeListener(this);
              newGameLUK.addChangeListener(this);
              newGameOK.setVisible(true);
              newGameName.setVisible(true);
              newGameRace.setVisible(true);
              newGameGender.setVisible(true);
              newGameSTR.setVisible(true);
              newGameAGI.setVisible(true);
              newGameVIT.setVisible(true);
              newGameDEX.setVisible(true);
              newGameINT.setVisible(true);
              newGameLUK.setVisible(true);
              nGameName.setVisible(true);
              nGameRace.setVisible(true);
              nGameGender.setVisible(true);
              nGameSTR.setVisible(true);
              nGameAGI.setVisible(true);
              nGameVIT.setVisible(true);
              nGameDEX.setVisible(true);
              nGameINT.setVisible(true);
              nGameLUK.setVisible(true);
              repaint();
         public void newGameGetInfo()//Grabs the information from the items in the New Game
              hero = new Chara();
              hero.name = newGameName.getText();
              hero.name = hero.name.trim();
              if(hero.name.length() > 10){hero.name = hero.name.substring(0, 10);}
              hero.race = (String)newGameRace.getSelectedItem();
              hero.gender = (String)newGameGender.getSelectedItem();
              for(int i = 0; i < 2; i ++)
                   hero.strength[i] = tempScrollA;
                   hero.agility[i] = tempScrollB;
                   hero.vitality[i] = tempScrollC;
                   hero.dexterity[i] = tempScrollD;
                   hero.intelligence[i] = tempScrollE;
                   hero.luck[i] = tempScrollF;
              if(hero.race == "Human")
                   hero.strength[2] = 1;
                   hero.agility[2] = 1;
                   hero.vitality[2] = 1;
                   hero.dexterity[2] = 1;
                   hero.intelligence[2] = 1;
                   hero.luck[2] = 1;
              if(hero.race == "Elf")
                   hero.strength[2] = 0;
                   hero.agility[2] = 2;
                   hero.vitality[2] = 0;
                   hero.dexterity[2] = 2;
                   hero.intelligence[2] = 2;
                   hero.luck[2] = 0;
              if(hero.race == "Dwarf")
                   hero.strength[2] = 3;
                   hero.agility[2] = 0;
                   hero.vitality[2] = 2;
                   hero.dexterity[2] = 0;
                   hero.intelligence[2] = 0;
                   hero.luck[2] = 1;
              int hp[] = new int[3];//Min/Max HP
              int mp[] = new int[3];//Min/Max SP
              hero.level = 1;
              hero.job = "Novice";
              hero.status = "Normal";
              hero.property = "Normal";
              for(int i = 0; i < hero.location.length; i++)
                   for(int a = 0; a < hero.location.length; a++)
                        hero.location[i][a] = 320;
              menuActivate();
              resetNewGameStuff();
              visiblePanelChecker();
         public void resetNewGameStuff()//Resets the values in the items for the New Game
              newGameName = null;
              newGameRace = newGameGender = null;
              newGameSTR = newGameAGI = newGameVIT = newGameDEX = newGameINT = newGameLUK = null;
              nGameSTR = nGameAGI = nGameVIT = nGameDEX = nGameINT = nGameLUK = null;

    Is there anybody who can help me? I need Help guys......

  • JComboBox Dropping Problem

    Hi, I have a JComboBox in a table cell with all the Item I need. But the problem is when I click on JComboBox, dropdown menu pops up and immediately hides automatically. And cannot allow me to choose anything.
    Any suggestions plz.
    Thanks

    You've got a coding problem, so read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html]How to Use Combo Boxes for example on how to do this correctly.

  • JComboBox MouseListener Problem

    Hi!
    I have problem in getting mouseEntered event from a JComboBox. I have registered a MouseListener with it but it doesn't fire any mouseEvent. Anyone has any idea how to get the mouseEntered Event fired from a JComboBox??
    Thanks!!

    Even I, have a similar problem. My obejective is to display the tooltip, When I move the mouse over every individual item in the combo box. The combo basically has a JList. So, I overrided the getListCellRenderer(...) method. It is not displaying the toolTip when the combo initially has no selectedItem. If there is a selected item, the first time itslef, it displays the toolTip. If theres no selectedItem, it displays the toolTip when I move the mouse out of the combo(when the combo is expanded). Tried all possible combinations... but doesnt work. Have set the toolTip with setToolTipText() method... and when I print the toolTip with getToolTipText() method. It prints correctly, but isnt getting displayed.. :-(

  • JComboBox Editing problem

    hi all ,
    I have problem with JComboBox
    like this :
    JComboBox comTech = new JComboBox();
    comTech.addItem(" ");
    comTech.addItem("one");
    comTech.addItem("two");
    the problem is I want first( comTech.addItem(" ");) item is Editable remaing are uneditable
    I am not getting any solution if anyone knows please send the solution
    thanks

    You missunderstand the use of JComboBox. A JComboBox is used to allow the user to selection from a list of items.
    An uneditable combox allows the user to select an item from the list.
    An editable combo box allows the user to select an item from the list or to enter there own value. It does not allow you to change the value of the entries in the list.
    See this section from the Swing tutorial on "How to Use Combo Boxes":
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

  • 2 JComboBox  sync problem

    Hi, im getting crazy with this error. I have two different JComboBox with two differents DefaultComboBoxModel.
    The first shows a list of files.
    The second shows a data list from the selected file in the first.
    When i select a different file in the first combo, i want to change the data list in the second combo. So i call the removeAllElements method in the DefaultComboBoxModel, but i dont know why, then the second combo code is executed too (it shouldnt) and i get an error.
    The code is something like this:
    cmb1 is a jcombobox linked to dcbm1, which is a defaultcomboboxmodel
    cmb2 is a jcombobox linked to dcbm2, which is a defaultcomboboxmodel
    MyObject is a customized class which has two fields: a Vector and a String. There is a Vector of MyObject, where is load the file data.
      void cmb1_actionPerformed(ActionEvent e){
        dcbm2.removeAllElements();
        // Load the file
        // Get data load on vector (class Vector)
        // Then, send data from vector to 2nd combomodel:
        for (int i=0; i<vector.size(); i++){
          mo = (MyObject)vector.get(i);
          dcbm2.addElement(mo.getString());
      void cmb2_actionPerformed(ActionEvent e){
        dlm.clear();                                                    // ListModel which i use to show data
        int x = cmb2.getSelectedIndex();
        m = (MyObject)vector.get(x);                       // This line throws the error (ArrayOutOfBounds). x=-1
        vector2 = m.getVector();
        for (int i=0; i<vector2.size(); i++){
          dlm.addElement((vector2.getString()
      }So thats my problem. When i select an item in the 1st combo, the 2nd combo code is executed too, throwing an ArrayIndexOutOfBounds because there is no item selected

    as I see, in this listing, you did not try using what I told you before, try using this:
    public void actionPerformed(ActionEvent e) {
         Object obj = e.getSource();
         if (obj == cmbFiles) {
              parser = new MyXMLParser((String) dcbmFiles.getSelectedItem());
              try {
                   carrera = parser.read();
              } catch (Exception z) {
                   z.printStackTrace();
              cursos = carrera.getCursos();
              for (int i = 0; i < cursos.size(); i++) {
                   cur = (Curso) cursos.get(i);
                   dcbmCursos.addElement(cur.getCurso());
         } else if (obj == cmbCursos) {
              dlmAsignaturas.clear();
              int x = cmbCursos.getSelectedIndex();
              cur = (Curso) cursos.get(x);
              asignaturas = cur.getAsignaturas();
              for (int i = 0; i < asignaturas.size(); i++) {
                   dlmAsignaturas.addElement(
                        ((Asignatura) asignaturas.get(i)).getId()
                             + ((Asignatura) asignaturas.get(i)).getGrupo().toLowerCase());
    }

  • JPasswordField and JButton Problem

    Happy New Year to all of you guys and gals. Here's the problem
    I have a String Array of buttons made already .. The design and measuring of the buttons are similar to a regular calculator.
    Now depending on the button that I press I set the text of the JPasswordField to "whatever", which is wrong because it's not being appended. So there has to be another way to do this.
    Take a calculator or bank for example. You press one button, it shows, and press the same button, so you have two digits appear on screen. That's exactly what I'm looking for. But I'm stuck...
    Here's the code to create the buttons
    for (int i = 0; i < 13; i++)
    button[i] = new JButton(Buttons);
    button[i].addActionListener(this);
    button[i].setFont(new Font("Comic Sans MS", Font.BOLD, 12));
    button[i].setSize(50, 30);
    button[i].setLocation(x, y);
    button[i].setBackground(Color.darkGray);
    button[i].setForeground(Color.white);
    button[i].setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.lightGray));
    theKeysP.add(button[i]);
    x = x + 50;
    if((i + 1) % 4 == 0)
    x = 210;
    y = y + 30;
    if(i == 12)
    button[i].setLocation(410, 65);
    button[i].setBackground(Color.green);
    button[i].setForeground(Color.black);
    Lets say starting from button 0 to 5 are numbers starting from 1 - 6
    Since I'm clicking on the button it's an ActionEvent,
    so If(e.getSource() == button[0])
    PF.setText("1"); //Wrong because it's not being appended. Therefore it resets everytime button[0] is clicked.
    I hope this I made clear enough. Can anyone provide suggestions for this problem.

    Try doing it this way instead
    password.setText( password.getText() + "1" );Next time please use the code tags when posting
    ICE

  • Solution to setRollOverIcon (for JButton) problem

    Hi all,
    I've seen a lot of posts asking why setRolloverIcon() didn't work. I had the same problem, and after looking throught the SwingSet example, I found the solution.
    So far, the only way that I've been able to get the rollover icon to work is through the following code:
    JToolBar toolBar = new JToolBar();
    JButton button = new JButton(defaultImage);
    toolBar.add(button);
    button.setRolloverIcon(rolloverImage);
    ...I don't know why, but if you set the rollover icon before you add the button to the toolbar (or whichever component you add the button to), the rollover icon doesn't work.
    Hope this helps.

    This is the class I generally use for toolbars.
    * Toolbar.java
    * Created on 29 September 2002, 21:01
    package org.argouml.ui;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.Insets;
    * @author  Bob Tarling
    public class Toolbar extends JToolBar {
        /** Creates a new instance of Toolbar */
        public Toolbar(String title) {
            this.setFloatable(true);
            this.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
            this.setMargin(new Insets(0,0,0,0));
        /** Creates a new instance of Toolbar */
        public Toolbar() {
            super();
            this.setFloatable(false);
            this.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
            this.setMargin(new Insets(0,0,0,0));
        public Toolbar(int orientation) {
            super(orientation);
            this.setFloatable(false);
            this.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
            this.setMargin(new Insets(0,0,0,0));
    }

Maybe you are looking for

  • How to write formula for 0calweek from 0calmonth

    Hi Friends, I'm doing weekly report. my infocube, data coming from three sources, two sources are ODS. In ODS doesn't have 0calweek only have 0calmonth. When i see my report i can't view those ODS data in the report. So i want write a formula. How do

  • Validity date issue: Access Enforcer

    Hi All, There is a request in Access Enforcer wherein there are total 4 stages of approval, the first 2 stages have been properly approved however when the same arrived to the 3rd stage of approval, the validity date for the request was over and ther

  • When we create a queue how many files get created???

    Hi All,           When we create a resource suppose a queue then how many files get created or modified from that action internally??           Thanks in advance           Sumeet

  • Video that are parts of album bought on iTunes: no images

    Hi everybody I just received my new apple TV. All my videos streamed from ipad3 or iphone 4s play well. Only the video that are "bonus" fromalbum bought on itunes wont play. Can only have the sound, but no image. Is it normal ? What can I do ? All ho

  • No Email on Bell BB 9360 with AIS sim in Thailand

    I have an unlocked Curve 9360 (usually on Bell Mobility in Canada). I'm currently in Thailand, so I put in a 1-2-Go sim card from AIS. Now my email won't work on either data or wifi. Neither does Facebook, but I don't care about that. What can I do t