SlideShare a Scribd company logo
1 of 10
Download to read offline
I have the following problem:
For Java GUI project, you will implement a simple Character Creation Screen as found in many
different RPGs (role playing games.) This screen will allow the user to pick and save a
character’s specifications from a list of options.
The interface must have the following:
(Radio Buttons) The user may select among three options for the character’s Gender:
Male
Female
Hermaphrodite
(A Drop-Down List) The user may select from among the following Professions for the
character:
Warrior, Barbarian, Monk, Mage, Thief
(A Text Field) The user may enter his/her character’s Name, which must be at least one character
long, but may be as long as 10 characters
(Sliders and a label) The user has 100 skill points to spend across 4 different passive skills. The
user will see a label with “100” on it originally. o Whenever he/she slides a slider to increase the
skill points in that skill, the points are taken from the 100 points (or however many are
remaining.)
When the user decreases the skill points in a particular area, they are returned to the “points left
to spend” pool, and this is reflected in the label as well. The remaining points will always be
displayed in this label.
If the player runs out of points to spend, he/she should not be able to increase the points in any
skill area until points are returned to the pool, and are available to be spent
The four (4) skill areas are as follows:
Intelligence, Dexterity, Strength, and Wisdom
There will be a Menu System for opening and saving a saved character.
The menu bar should contain two titles: File and Options
Under the File Menu, there are two options:
Open a saved character
Save a character
Under the Options Menu, there are two options:
Reset All
Exit File
Open (a Saved Character)
With this option, you should be able to open a saved character file, for example, Bob.player or
Sue.player
The character’s information will be read into the program and all the components on the GUI
will be set accordingly, as if the user had just entered them. If the user makes changes, these
changes should overwrite the current file (upon a save.)
File Save (a Character)
This option allows the user to save the current player he/she is working on. The file will contain
information that represents the state of the GUI and must be readable by the Open option. The
file must be saved as character_name.player.
You should prompt the user and say “Are you sure you want to save this charcter?” before they
actually save it. Your dialog prompt should allow the user to Cancel the save if he/she so desires.
Reset All
Reset All sets all the GUI components to their zero state. Note that this option does not
automatically save the character data.
Exit
This is self-explanatory. Close the Character Creation application.
How do you I do this with the following code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.io.*;
import java.util.*;
public class Character extends JFrame
{
//Constants for window width and height
private final int WINDOW_WIDTH = 1500;
private final int WINDOW_HEIGHT = 250;
//Character gender
private JRadioButton male;
private JRadioButton female;
private JRadioButton hermaphrodite ;
//Character Name and Class
private JTextField characterName;
private JComboBox proffesion;
//Character Stats
private JSlider intelligence;
private JSlider dexterity;
private JSlider strength;
private JSlider wisdom;
//Groups gender
private ButtonGroup characterGender;
//Panel groups
private JPanel gender;
private JPanel namePanel;
private JPanel intelPanel;
private JPanel dexPanel;
private JPanel strengthPanel;
private JPanel wisdomPanel;
// CONSTRUCTOR
public Character()
{
//Window title
setTitle("Character Sheet");
//Set size
setSize(WINDOW_WIDTH,WINDOW_HEIGHT);
//Default close operation
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Calling buildPanel method
buildPanels();
//Grid Layout
setLayout(new FlowLayout());
//Adding the panel to JFrame
add(gender);
add(namePanel);
add(intelPanel);
add(dexPanel);
add(strengthPanel);
add(wisdomPanel);
//Visibility
setVisible(true);
// Creates a menubar for a JFrame
JMenuBar menuBar = new JMenuBar();
// Add the menubar to the frame
setJMenuBar(menuBar);
// Define and add two drop down menu to the menubar
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Option");
menuBar.add(fileMenu);
menuBar.add(editMenu);
// Create and add simple menu item to one of the drop down menu
JMenuItem resetAction = new JMenuItem("Reset all");
JMenuItem openAction = new JMenuItem("Open a saved character");
JMenuItem exitAction = new JMenuItem("Exit");
JMenuItem saveAction = new JMenuItem("Save");
// Create a Menu ButtonGroup
ButtonGroup bg = new ButtonGroup();
fileMenu.add(openAction);
fileMenu.add(saveAction);
editMenu.add(resetAction);
editMenu.add(exitAction);
// Create JSLider
JSlider intelligence = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
JSlider dexterity = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
JSlider strength = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
JSlider wisdom = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
}
// Building the Panels,
private void buildPanels()
{
//Initializing butons
male = new JRadioButton("Male");
female = new JRadioButton("Female");
hermaphrodite = new JRadioButton("Hermaphrodite");
characterGender = new ButtonGroup();
characterGender.add(male);
characterGender.add(female);
characterGender.add(hermaphrodite);
//Initializing TextField and JComboBox
characterName = new JTextField(10);
String[] classes = { "Warrior", "Barbarian", "Monk", "Mage", "Thief" };
JComboBox proffesion = new JComboBox(classes);
//Initializing JSlider
intelligence = new JSlider();
dexterity = new JSlider();
strength = new JSlider();
wisdom = new JSlider();
//Initializing the panels
gender = new JPanel();
namePanel = new JPanel();
intelPanel = new JPanel();
dexPanel = new JPanel();
strengthPanel= new JPanel();
wisdomPanel = new JPanel();
//Setting borders of the panels
gender.setBorder(BorderFactory.createTitledBorder("Gender"));
namePanel.setBorder(BorderFactory.createTitledBorder("Name and Class"));
intelPanel.setBorder(BorderFactory.createTitledBorder("Intelligence"));
dexPanel.setBorder(BorderFactory.createTitledBorder("Dexterity"));
strengthPanel.setBorder(BorderFactory.createTitledBorder("Strength"));
wisdomPanel.setBorder(BorderFactory.createTitledBorder("Wisdom"));
//Adding the objecs to the respective panels
gender.add(male);
gender.add(female);
gender.add(hermaphrodite);
namePanel.add(characterName);
namePanel.add(proffesion);
//Creating Stats and
int startValue = 0;
intelPanel.add(intelligence);
intelligence.setValue(startValue);
intelligence.setMajorTickSpacing(25);
intelligence.setMinorTickSpacing(25);
intelligence.setPaintTicks(true);
intelligence.setPaintLabels(true);
dexPanel.add(dexterity);
dexterity.setValue(startValue);
dexterity.setMajorTickSpacing(25);
dexterity.setMinorTickSpacing(25);
dexterity.setPaintTicks(true);
dexterity.setPaintLabels(true);
strengthPanel.add(strength);
strength.setValue(startValue);
strength.setMajorTickSpacing(25);
strength.setMinorTickSpacing(25);
strength.setPaintTicks(true);
strength.setPaintLabels(true);
wisdomPanel.add(wisdom);
wisdom.setValue(startValue);
wisdom.setMajorTickSpacing(25);
wisdom.setMinorTickSpacing(25);
wisdom.setPaintTicks(true);
wisdom.setPaintLabels(true);
//Associating action listener
// Open.addActionListener(new OpenButtonListener());
//Save.addActionListener(new SaveButtonListener());
//Reset.addActionListener(new ResetButtonListener());
//Exit.addActionListener(new ExitButtonListener());
}//End buildPanels
/**
Action listener
*/
private class OpenButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent openaction)
{
}
}
private class SaveButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent saveaction)
{
}
}
private class ResetButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent resetaction)
{
}
}
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent exitaction)
{
}
}
public static void main(String[] args)throws IOException
{
new Character();
}
}
Solution
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Draw{
JFrame frame;
Canvas canvas;
BufferStrategy bufferStrategy;
private int WIDTH = 1500;
private int HEIGHT = 250;
Draw(){
frame = new JFrame("Basic Game");
JPanel panel = (JPanel) frame.getContentPane();
panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
panel.setLayout(null);
canvas = new Canvas();
canvas.setBounds(0, 0, WIDTH, HEIGHT);
canvas.setIgnoreRepaint(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
panel.add(canvas);
canvas.createBufferStrategy(2);
bufferStrategy = canvas.getBufferStrategy();
canvas.requestFocus();
canvas.setBackground(Color.black);
canvas.addKeyListener(new ButtonHandler());
}
void render() {
Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
g.clearRect(0, 0, WIDTH, HEIGHT);
render(g);
g.dispose();
bufferStrategy.show();
}
protected void render(Graphics2D g){
}
}

More Related Content

Similar to I have the following problemFor Java GUI project, you will implem.pdf

Whenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdfWhenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdf
aarthitimesgd
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
aggarwalshoppe14
 
TASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdfTASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdf
indiaartz
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
venkt12345
 
Lab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docxLab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docx
smile790243
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
ARORACOCKERY2111
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
aggarwalshoppe14
 

Similar to I have the following problemFor Java GUI project, you will implem.pdf (20)

Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJSAprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Whenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdfWhenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdf
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
 
TASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdfTASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdf
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
 
Lab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docxLab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docx
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
 
Web Development Study Jam #2 _ Basic JavaScript.pptx
Web Development Study Jam #2 _ Basic JavaScript.pptxWeb Development Study Jam #2 _ Basic JavaScript.pptx
Web Development Study Jam #2 _ Basic JavaScript.pptx
 
jQuery Anti-Patterns for Performance
jQuery Anti-Patterns for PerformancejQuery Anti-Patterns for Performance
jQuery Anti-Patterns for Performance
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
Earthworm Platformer Package
Earthworm Platformer PackageEarthworm Platformer Package
Earthworm Platformer Package
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
 
JavaFXScript
JavaFXScriptJavaFXScript
JavaFXScript
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
 

More from rajkumarm401

Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
rajkumarm401
 
eee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdfeee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdf
rajkumarm401
 
Essay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdfEssay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdf
rajkumarm401
 
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdfDescribe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
rajkumarm401
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
rajkumarm401
 
Click the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdfClick the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdf
rajkumarm401
 
What was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdfWhat was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdf
rajkumarm401
 
This is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfThis is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdf
rajkumarm401
 
Program Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfProgram Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdf
rajkumarm401
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
rajkumarm401
 

More from rajkumarm401 (20)

Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
 
Explain the characterstic of web service techonolgy.SolutionT.pdf
Explain the characterstic of web service techonolgy.SolutionT.pdfExplain the characterstic of web service techonolgy.SolutionT.pdf
Explain the characterstic of web service techonolgy.SolutionT.pdf
 
Executive Summary i. Provide a succinct overview of your strategic p.pdf
Executive Summary i. Provide a succinct overview of your strategic p.pdfExecutive Summary i. Provide a succinct overview of your strategic p.pdf
Executive Summary i. Provide a succinct overview of your strategic p.pdf
 
eee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdfeee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdf
 
Essay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdfEssay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdf
 
During oogenesis, will the genotypes of the first and second polar b.pdf
During oogenesis, will the genotypes of the first and second polar b.pdfDuring oogenesis, will the genotypes of the first and second polar b.pdf
During oogenesis, will the genotypes of the first and second polar b.pdf
 
Does personal information available on the Internet make an employee.pdf
Does personal information available on the Internet make an employee.pdfDoes personal information available on the Internet make an employee.pdf
Does personal information available on the Internet make an employee.pdf
 
Determine whether each series is convergent or divergent..pdf
Determine whether each series is convergent or divergent..pdfDetermine whether each series is convergent or divergent..pdf
Determine whether each series is convergent or divergent..pdf
 
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdfDescribe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
 
Click the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdfClick the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdf
 
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfYOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
 
What was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdfWhat was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdf
 
Transactions costs are zero in financial markets. zero in financial i.pdf
Transactions costs are zero in financial markets. zero in financial i.pdfTransactions costs are zero in financial markets. zero in financial i.pdf
Transactions costs are zero in financial markets. zero in financial i.pdf
 
This is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfThis is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdf
 
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
Question 34 (1 point) D A check is 1) not money because it is not off.pdfQuestion 34 (1 point) D A check is 1) not money because it is not off.pdf
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
 
Program Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfProgram Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdf
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
Need help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdfNeed help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdf
 
mine whether the following s are true or false False A parabola has e.pdf
mine whether the following s are true or false False A parabola has e.pdfmine whether the following s are true or false False A parabola has e.pdf
mine whether the following s are true or false False A parabola has e.pdf
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

I have the following problemFor Java GUI project, you will implem.pdf

  • 1. I have the following problem: For Java GUI project, you will implement a simple Character Creation Screen as found in many different RPGs (role playing games.) This screen will allow the user to pick and save a character’s specifications from a list of options. The interface must have the following: (Radio Buttons) The user may select among three options for the character’s Gender: Male Female Hermaphrodite (A Drop-Down List) The user may select from among the following Professions for the character: Warrior, Barbarian, Monk, Mage, Thief (A Text Field) The user may enter his/her character’s Name, which must be at least one character long, but may be as long as 10 characters (Sliders and a label) The user has 100 skill points to spend across 4 different passive skills. The user will see a label with “100” on it originally. o Whenever he/she slides a slider to increase the skill points in that skill, the points are taken from the 100 points (or however many are remaining.) When the user decreases the skill points in a particular area, they are returned to the “points left to spend” pool, and this is reflected in the label as well. The remaining points will always be displayed in this label. If the player runs out of points to spend, he/she should not be able to increase the points in any skill area until points are returned to the pool, and are available to be spent The four (4) skill areas are as follows: Intelligence, Dexterity, Strength, and Wisdom There will be a Menu System for opening and saving a saved character. The menu bar should contain two titles: File and Options Under the File Menu, there are two options: Open a saved character Save a character Under the Options Menu, there are two options: Reset All Exit File Open (a Saved Character)
  • 2. With this option, you should be able to open a saved character file, for example, Bob.player or Sue.player The character’s information will be read into the program and all the components on the GUI will be set accordingly, as if the user had just entered them. If the user makes changes, these changes should overwrite the current file (upon a save.) File Save (a Character) This option allows the user to save the current player he/she is working on. The file will contain information that represents the state of the GUI and must be readable by the Open option. The file must be saved as character_name.player. You should prompt the user and say “Are you sure you want to save this charcter?” before they actually save it. Your dialog prompt should allow the user to Cancel the save if he/she so desires. Reset All Reset All sets all the GUI components to their zero state. Note that this option does not automatically save the character data. Exit This is self-explanatory. Close the Character Creation application. How do you I do this with the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; import java.io.*; import java.util.*; public class Character extends JFrame { //Constants for window width and height private final int WINDOW_WIDTH = 1500; private final int WINDOW_HEIGHT = 250; //Character gender private JRadioButton male; private JRadioButton female; private JRadioButton hermaphrodite ; //Character Name and Class private JTextField characterName; private JComboBox proffesion;
  • 3. //Character Stats private JSlider intelligence; private JSlider dexterity; private JSlider strength; private JSlider wisdom; //Groups gender private ButtonGroup characterGender; //Panel groups private JPanel gender; private JPanel namePanel; private JPanel intelPanel; private JPanel dexPanel; private JPanel strengthPanel; private JPanel wisdomPanel; // CONSTRUCTOR public Character() { //Window title setTitle("Character Sheet"); //Set size setSize(WINDOW_WIDTH,WINDOW_HEIGHT); //Default close operation setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Calling buildPanel method buildPanels(); //Grid Layout setLayout(new FlowLayout());
  • 4. //Adding the panel to JFrame add(gender); add(namePanel); add(intelPanel); add(dexPanel); add(strengthPanel); add(wisdomPanel); //Visibility setVisible(true); // Creates a menubar for a JFrame JMenuBar menuBar = new JMenuBar(); // Add the menubar to the frame setJMenuBar(menuBar); // Define and add two drop down menu to the menubar JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Option"); menuBar.add(fileMenu); menuBar.add(editMenu); // Create and add simple menu item to one of the drop down menu JMenuItem resetAction = new JMenuItem("Reset all"); JMenuItem openAction = new JMenuItem("Open a saved character"); JMenuItem exitAction = new JMenuItem("Exit"); JMenuItem saveAction = new JMenuItem("Save"); // Create a Menu ButtonGroup ButtonGroup bg = new ButtonGroup(); fileMenu.add(openAction); fileMenu.add(saveAction); editMenu.add(resetAction); editMenu.add(exitAction);
  • 5. // Create JSLider JSlider intelligence = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); JSlider dexterity = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); JSlider strength = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); JSlider wisdom = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); } // Building the Panels, private void buildPanels() { //Initializing butons male = new JRadioButton("Male"); female = new JRadioButton("Female"); hermaphrodite = new JRadioButton("Hermaphrodite"); characterGender = new ButtonGroup(); characterGender.add(male); characterGender.add(female); characterGender.add(hermaphrodite); //Initializing TextField and JComboBox characterName = new JTextField(10); String[] classes = { "Warrior", "Barbarian", "Monk", "Mage", "Thief" }; JComboBox proffesion = new JComboBox(classes); //Initializing JSlider intelligence = new JSlider(); dexterity = new JSlider(); strength = new JSlider(); wisdom = new JSlider(); //Initializing the panels gender = new JPanel();
  • 6. namePanel = new JPanel(); intelPanel = new JPanel(); dexPanel = new JPanel(); strengthPanel= new JPanel(); wisdomPanel = new JPanel(); //Setting borders of the panels gender.setBorder(BorderFactory.createTitledBorder("Gender")); namePanel.setBorder(BorderFactory.createTitledBorder("Name and Class")); intelPanel.setBorder(BorderFactory.createTitledBorder("Intelligence")); dexPanel.setBorder(BorderFactory.createTitledBorder("Dexterity")); strengthPanel.setBorder(BorderFactory.createTitledBorder("Strength")); wisdomPanel.setBorder(BorderFactory.createTitledBorder("Wisdom")); //Adding the objecs to the respective panels gender.add(male); gender.add(female); gender.add(hermaphrodite); namePanel.add(characterName); namePanel.add(proffesion); //Creating Stats and int startValue = 0; intelPanel.add(intelligence); intelligence.setValue(startValue); intelligence.setMajorTickSpacing(25); intelligence.setMinorTickSpacing(25); intelligence.setPaintTicks(true); intelligence.setPaintLabels(true); dexPanel.add(dexterity); dexterity.setValue(startValue); dexterity.setMajorTickSpacing(25); dexterity.setMinorTickSpacing(25);
  • 7. dexterity.setPaintTicks(true); dexterity.setPaintLabels(true); strengthPanel.add(strength); strength.setValue(startValue); strength.setMajorTickSpacing(25); strength.setMinorTickSpacing(25); strength.setPaintTicks(true); strength.setPaintLabels(true); wisdomPanel.add(wisdom); wisdom.setValue(startValue); wisdom.setMajorTickSpacing(25); wisdom.setMinorTickSpacing(25); wisdom.setPaintTicks(true); wisdom.setPaintLabels(true); //Associating action listener // Open.addActionListener(new OpenButtonListener()); //Save.addActionListener(new SaveButtonListener()); //Reset.addActionListener(new ResetButtonListener()); //Exit.addActionListener(new ExitButtonListener()); }//End buildPanels /** Action listener */ private class OpenButtonListener implements ActionListener { public void actionPerformed(ActionEvent openaction) { } }
  • 8. private class SaveButtonListener implements ActionListener { public void actionPerformed(ActionEvent saveaction) { } } private class ResetButtonListener implements ActionListener { public void actionPerformed(ActionEvent resetaction) { } } private class ExitButtonListener implements ActionListener { public void actionPerformed(ActionEvent exitaction) { } } public static void main(String[] args)throws IOException { new Character(); } } Solution import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension;
  • 9. import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import javax.swing.JFrame; import javax.swing.JPanel; public class Draw{ JFrame frame; Canvas canvas; BufferStrategy bufferStrategy; private int WIDTH = 1500; private int HEIGHT = 250; Draw(){ frame = new JFrame("Basic Game"); JPanel panel = (JPanel) frame.getContentPane(); panel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); panel.setLayout(null); canvas = new Canvas(); canvas.setBounds(0, 0, WIDTH, HEIGHT); canvas.setIgnoreRepaint(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setResizable(false); frame.setVisible(true); panel.add(canvas); canvas.createBufferStrategy(2); bufferStrategy = canvas.getBufferStrategy(); canvas.requestFocus(); canvas.setBackground(Color.black); canvas.addKeyListener(new ButtonHandler()); } void render() { Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics(); g.clearRect(0, 0, WIDTH, HEIGHT); render(g); g.dispose(); bufferStrategy.show();