Created
August 21, 2015 17:03
-
-
Save lordgmage/675afbcb746e21e6b00b to your computer and use it in GitHub Desktop.
combo box not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import data.Constants; | |
import data.Variables; | |
import java.awt.BorderLayout; | |
import java.awt.EventQueue; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.border.EmptyBorder; | |
import javax.swing.SpringLayout; | |
import javax.swing.JLabel; | |
import java.awt.Font; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.SwingConstants; | |
import javax.swing.JToggleButton; | |
import javax.swing.JRadioButton; | |
import javax.swing.JTextField; | |
import javax.swing.JButton; | |
import javax.swing.JComboBox; | |
import javax.swing.DefaultComboBoxModel; | |
public class UI extends JFrame { | |
private JPanel contentPane; | |
private JTextField txtPleaseEnterPlayers; | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
UI frame = new UI(); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
/** | |
* Create the frame. | |
*/ | |
public UI() { | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 450, 300); | |
contentPane = new JPanel(); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
contentPane.setLayout(new BorderLayout(0, 0)); | |
setContentPane(contentPane); | |
JPanel panel = new JPanel(); | |
contentPane.add(panel, BorderLayout.CENTER); | |
panel.setLayout(null); | |
JLabel lblLordPrayer = new JLabel("Lord Prayer"); | |
lblLordPrayer.setBounds(146, 11, 138, 29); | |
lblLordPrayer.setHorizontalAlignment(SwingConstants.CENTER); | |
lblLordPrayer.setFont(new Font("Myriad Pro Light", Font.PLAIN, 28)); | |
JRadioButton rdbtnBuryBones = new JRadioButton("Bury Bones"); | |
rdbtnBuryBones.setBounds(6, 128, 94, 50); | |
panel.add(rdbtnBuryBones); | |
JRadioButton rdbtnOtherHouse = new JRadioButton("Other house"); | |
rdbtnOtherHouse.setBounds(6, 181, 85, 42); | |
panel.add(rdbtnOtherHouse); | |
txtPleaseEnterPlayers = new JTextField(); | |
txtPleaseEnterPlayers.setText("Please enter players name"); | |
txtPleaseEnterPlayers.setToolTipText("Other player house name"); | |
txtPleaseEnterPlayers.setBounds(146, 196, 152, 20); | |
panel.add(txtPleaseEnterPlayers); | |
txtPleaseEnterPlayers.setColumns(10); | |
JComboBox comboBox = new JComboBox(); | |
comboBox.setModel(new DefaultComboBoxModel(new String[]{"Bones", "Bat Bones", "Big Bones", "Dragon Bones"})); | |
comboBox.setBounds(109, 143, 305, 20); | |
panel.add(comboBox); | |
JButton btnStart = new JButton("Start"); | |
btnStart.setBounds(6, 229, 418, 23); | |
panel.add(btnStart); | |
btnStart.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
StartButtonActionPerformed(); | |
} | |
}); | |
} | |
private void StartButtonActionPerformed(){ | |
switch (comboBox.getSelectedIndex()) { | |
case 0: | |
Variables.bones = Constants.BONES; | |
break; | |
case 1: | |
Variables.bones = Constants.BAT_BONES; | |
break; | |
case 2: | |
Variables.bones = Constants.BIG_BONES; | |
break; | |
case 3: | |
Variables.bones = Constants.DRAGON_BONES; | |
break; | |
default: | |
System.out.println("Something wrong as happened please contact the script writers."); | |
break; | |
} | |
if (rdbtnBuryBones.isSelected()) { | |
Variables.setBurybones(true); | |
} else { | |
Variables.setBurybones(false); | |
} | |
Variables.setStartScript(true); | |
setVisible(false); | |
} | |
private final JComboBox comboBox = new JComboBox(); | |
private final JToggleButton rdbtnBuryBones = new JToggleButton("Power Bury"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment