For Java Swing project, you will implement a simple Character Creation Screen as
ID: 3775808 • Letter: F
Question
For Java Swing 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.
Explanation / Answer
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 = 640;
private int HEIGHT = 480;
Draw(){
//Makes a new window, with the name " Basic game ".
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();
//this will make the frame not re-sizable
frame.setResizable(false);
frame.setVisible(true);
//this will add the canvas to our frame
panel.add(canvas);
canvas.createBufferStrategy(2);
bufferStrategy = canvas.getBufferStrategy();
//This will make sure the canvas has focus, so that it can take input from mouse/keyboard
canvas.requestFocus();
//this will set the background to black
canvas.setBackground(Color.black);
// This will add our buttonhandler to our program
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){
//Here we will render everything
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.