Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do i keep the program running in Jgrasp. Like after i press OK from Choose Race, i want the Choose Class window from public

How do i keep the program running in Jgrasp. Like after i press OK from Choose Race, i want the Choose Class window from public void Custom() to open. Then after pressing OK again, i want it to move onto public void Side() and open the window. Then after pressing OK again, i want it to move onto public void Name() Thank you

import javax.swing.*; import java.awt.event.*; import javax.swing.JOptionPane;

/* Character creation simulator */ public class Character extends JFrame { private JButton button1; private JButton button2; private JButton button3; private JButton button4; private JButton button5; private JPanel panel; private JPanel panel2; private JPanel panel3; private final int WINDOW_WIDTH = 450; private final int WINDOW_HEIGHT = 100;

public Character() { setTitle("Choose Race"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); button1 = new JButton("Orc"); button2 = new JButton("Zombie"); button3 = new JButton("Elf"); button4 = new JButton("Fairy"); button5 = new JButton("Human"); button1.addActionListener(new ButtonListener()); button2.addActionListener(new ButtonListener()); button3.addActionListener(new ButtonListener()); button4.addActionListener(new ButtonListener()); button5.addActionListener(new ButtonListener()); panel = new JPanel(); panel.add(button1); panel.add(button2); panel.add(button3); panel.add(button4); panel.add(button5); add(panel); setVisible(true); } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) {

if (e.getSource() == button1) { JOptionPane.showMessageDialog(null, "You chose " + "Orc."); } else if (e.getSource() == button2) { JOptionPane.showMessageDialog(null, "You chose " + "Zombie."); } else if (e.getSource() == button3) { JOptionPane.showMessageDialog(null, "You chose " + "Elf."); } else if (e.getSource() == button4) { JOptionPane.showMessageDialog(null, "You chose " + "Fairy."); } else if (e.getSource() == button5) { JOptionPane.showMessageDialog(null, "You chose " + "Human."); } } } public void Custom() { setTitle("Choose Class"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); button1 = new JButton("Knight"); button2 = new JButton("Binder"); button3 = new JButton("Archer"); button4 = new JButton("Trickster"); button5 = new JButton("Magician"); button1.addActionListener(new ButtonListener2()); button2.addActionListener(new ButtonListener2()); button3.addActionListener(new ButtonListener2()); button4.addActionListener(new ButtonListener2()); button5.addActionListener(new ButtonListener2()); panel2 = new JPanel(); panel2.add(button1); panel2.add(button2); panel2.add(button3); panel2.add(button4); panel2.add(button5); add(panel); setVisible(true); }

private class ButtonListener2 implements ActionListener { public void actionPerformed(ActionEvent e) {

if (e.getSource() == button1) { JOptionPane.showMessageDialog(null, "You chose " + "Knight."); } else if (e.getSource() == button2) { JOptionPane.showMessageDialog(null, "You chose " + "Binder."); } else if (e.getSource() == button3) { JOptionPane.showMessageDialog(null, "You chose " + "Archer."); } else if (e.getSource() == button4) { JOptionPane.showMessageDialog(null, "You chose " + "Trickster."); } else if (e.getSource() == button5) { JOptionPane.showMessageDialog(null, "You chose " + "Magician."); } } }

public void Side() { setTitle("Choose Your Side!"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); button1 = new JButton("Light"); button2 = new JButton("Darkness"); button1.addActionListener(new ButtonListener3()); button2.addActionListener(new ButtonListener3()); panel3 = new JPanel(); panel3.add(button1); panel3.add(button2); add(panel); setVisible(true); }

private class ButtonListener3 implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { JOptionPane.showMessageDialog(null, "You chose " + "Light!."); } else if (e.getSource() == button2) { JOptionPane.showMessageDialog(null, "You chose " + "DARKNESS"); }

} }

public void Name()

{

String name; name = JOptionPane.showInputDialog( "What is your name?");

System.exit(0); }

public static void main(String[] args) { new Character(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

a. How are members selected to join the team?

Answered: 1 week ago

Question

b. What are its goals and objectives?

Answered: 1 week ago