Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click
Mar 16, 2015
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
Here is the code from my CardLayout:
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
[Code] ....
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
[Code] ....
Once again kept to a minimal.
View Replies
ADVERTISEMENT
Jun 19, 2014
I am trying to switch panel on click of a button but nothing is happening.
package game.uno.swings;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;
[Code] ....
I read the oracle doc example, i understand the concept but still nothing is happening on show,first ,next method of CardLayout in ActionPerformed. Code is highlighted where I am facing problem.
View Replies
View Related
Nov 7, 2014
i would like to create a menu like below where if i clicked on "DRAW", a frame to draw will appear and when i clicked on animate, I can animate an object drawn. I tried on using JButton, but I donno how to customize the design n so I would like to know is there other ways so tat my menu will appear as below?
View Replies
View Related
Apr 22, 2015
The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:
Reads file: Beginningbalance.txt
Displays Data with calculation
Creates a file called "Newbalance.txt" with the following values:
111
251.41
222
402.00
With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.
import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Output {
public static void main(String[]args) throws IOException {
[Code] .....
View Replies
View Related
Jan 12, 2015
So it seems to reason that many JavaFX applications will want to dynamically change CSS styles. Is the best way to do this via the <node>.getStyleClass().add("classname")? The underlying data structure is an observable list. So lets say one has 5 styles that simply change the fill color of a circle to 5 different colors respectively. So if I have a condition in which I want to dynamically apply 1 of these 5 styles, the way I currently do this is by defining all 5 styles as strings in a list using a static initializer, then I call <node>.getStyleClass().removeAll(list), then getStyleClass().add("classname"). I do this to avoid adding the same style over and over and inflating the underlying list. Is this the correct way to manage dynamic CSS styles?
So I know there is a few different way to implement a splash screen. My app has definitely gotten larger over the last few months of development and I have noticed there is about a 5 second delay between when I run the application to when I see the main stage. I was thinking a splash screen would be nice to fill this time period. I have not had time to prototype using a Preloader and I fear that using an alternate, lightweight stage on startup would still take too long of a delay. I was actually thinking that using the nice and simple JVM argument "-splash:<image name>" would be simple, easy and effective. Unfortunately when I try to do this, the splash screen comes up but never goes away.
View Replies
View Related
Apr 11, 2014
Tank war game thats ran over a network and is multiplayer, however whenever I fire a bullet it shows on my screen but not the other player's screen. Here's the code:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
import java.net.*;
import java.io.*;
[Code] ....
View Replies
View Related
Apr 11, 2014
I am currently making a 5 card stud game for my Java Programming class at my highschool. I am deciding to go a little above expectations and make my poker game a little more fun than just comparing a few cards. However I want there to be text that is changing on my screen, but the repaint() is not the most reliable way to make the screen update, I am wanting a way for have the program constantly update the screen so that if I do something like someLabel.setText("Text"); then the text will update automatically whenever it is changed.
Here is my declarations and main/constructor method
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class FiveCard extends JFrame implements ActionListener {
[Code] .....
Here is the method addMainPage, which is called in the constructor. Whenever the enterButton is pressed, the actionListener directs it to loadBoard();
I use GridBag Layout, so to skip through all of the constraints
public void addMainPage() {
for (int i = 0; i < 4; i++) {
players[i] = new Player();
}
Icon cardBackImage = new ImageIcon("back.gif");
[Code] .....
Game intro is a method that changes the text of a label every second using .setText(), however it does not work because the enterButton is pressed, then after loadBoard() and gameIntro() is ran, it repaints the frame with the board objects and the gameIntro's final .setText() command.The action listener is simple...
public void actionPerformed(ActionEvent e) {
if (e.getSource() == enterButton) {
players[0].setName(playerNameField.getText());
loadBoard();
}
p.repaint();
}
View Replies
View Related
Apr 13, 2014
Tank war game thats ran over a network and is multiplayer, however whenever I fire a bullet it shows on my screen but not the other player's screen. Here's a snippet of code form where i think the problem is coming from:
class Tank implements Ball {
double locX, locY, radius, angle;
int self; // index of this tank in WarPanel.tanks
public boolean turnL, turnR, forth, back, fire;
boolean prevtL, prevtR, prevfo;
Color color;
[Code] ....
View Replies
View Related
Jan 14, 2014
I am making a game with java in a program called greenfoot.My problem is that a sound won't play when the player dies and a Game Over screen pops up..
- I have saved the audio file in my sound map of the scenario
- Applied the good name of the file
- tested the sound effect and it's working
this is my code:
public GameOver()
{
setImage(new GreenfootImage("GAME OVER", 100, Color.BLACK, null));
Greenfoot.playSound("fail-trombone-03.wav");
Greenfoot.stop();
}
View Replies
View Related
Oct 5, 2014
The following class is part of a homework assignment:
package event;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import model.Model;
import shapes.Rectangle;
import shapes.Shape;
[Code] .....
I have to implement the methods for what is happening if on some panel the action selected are Remove/Move/Change/Resize (Draw is already implemented).
The Applet in question draws ovals or rectangles on the screen and you can change the fill-color and outline-color of the shape. All this works already. I have dabbled with the move-method, but am not going anywhere.
View Replies
View Related
Jun 4, 2014
This is code for a game I am making where you are a character at the bottom of the screen dodging falling rocks. I was wondering how to add in the falling rocks. I think I need to use Timer and an ArrayList but I am not sure if that would work and not truly sure how to go about doing it.
import java.applet.Applet;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import javax.imageio.ImageIO;
[Code] .....
View Replies
View Related
Dec 5, 2014
I want to create a Jtable when i click on "new" on the menu bar,but if i click on it, i still not see the table.Here is the code:
package mestint
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;
[code].....
View Replies
View Related
Oct 16, 2014
The gist of it is to create a very basic memory game. There are 12 buttons, each associated with an icon. Every button that you click will display the icon and will stay there until clicked again. I got the bulk of it taken care of, but my issue lies with switching the icons back and forth. I can get them to display one at a time, but when I click on a new button, all the icons except the button I just clicked don't display. Essentially, only one shows up at a time.
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.SwingConstants;
[code]....
View Replies
View Related
Mar 24, 2014
this is my first java game im making i tried to add tiles to the screen but i just get a black screen with no errors?
View Replies
View Related
Apr 2, 2014
How to clear console screen ? I am using Linux machine.
1) Runtime.getRuntime().exec("clear"); // this is not working. Not clearing the screen
2) for ( int i = 0; i < SOME_NUMBER; i++)
System.out.println();
2nd way is working but i think it is not a good option as i need to move scroll bar again and again.
View Replies
View Related
Oct 9, 2014
in my JSF2 app I have screens composed with :
- Header
- Body
In the header I have a combo list. At each change in value in the combo list I have an Ajax request that updates the data in the Body. So far everything is working properly. Now the home screen's structure should be change when the value of combo list change. To do this I have :
- 1 ManagedBean HomeBean that manage the home
- 1 ManagedBean HeaderBean that manage the header
- 2 object HomeScreen1.java and HomeScreen2.java that allows me to valued data from each screen
- 2 services HomeScreen1Loader.java and HomeScreen2Loader.java that manage loading of each type of screen
- 1 template home.xhtml
- 2 fichier home1.xhtml et home2.xhtml
When I log in to the application, I get the good page corresponding (Element type 1 => home page 1). But when I select a type 2 item, the actionListener methode is execute, ManagedBean's data was updated (for type 2 screen) , but the page does not updated. What do you do ?
HeaderBean.java :
package com.omb.view;
import java.io.Serializable;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
[Code] .....
View Replies
View Related
Jan 30, 2014
I was working on adding a selector on the screen. Searching for code, I found something that some created better than I ever could. I'm trying to integrate it into my code.
I have a program that is pretty MVC.
I'm in my controller class and I'm calling this code:
java - Drawing a bounding rectangle to select what area to record - Stack Overflow
I've changed it to a runnable and called a wait after I called this class, but it still continues on to the next line.
I'm thinking I'll have to either create a super controller (one that manages two controllers and have a multiple set of views and models) because I'll have multiple views or I'll have to figure out how to wait for it to finish as a thread. As mentioned above, wait() doesn't work.
This is the code in my controller after I changed it back from a Runnable:
SelectionRectangle m_rect = new SelectionRectangle();
//Thread m_thread = new Thread(m_rect);
//m_thread.start();
TopLeft = m_rect.getTopLeft();
BottomRight = m_rect.getBottomRight();
C_view.setText(TopLeft.toString());
View Replies
View Related
Apr 29, 2014
I'm having an issue with a swing application I'm working on. Java version is 4 (I know...). I have a main screen panel with multiple sub-panels (rows). Each of these row panels contains an additional 2 sub-panels. One of these 2 sub-panels contains buttons. When 1 button is pressed, I want to disable all of the buttons on-screen (or any other way of blocking user input) until a background event finishes. The row panels do not know about each other.
The first thing I have tried doing is, when a button is pressed, getting the parent. Using the parent I then iterate through its components, and so on until I'm iterating through the buttons. For each button, I am doing a .setEnabled(false); However, this does not work, why. I've also tried wrapping this process in SwingUtilities.invokeLater() out of desperation, but that didn't work either.
What would be the cleanest way to disable all buttons? Or block all user input? I've also tried adding an opaque dialog which hasn't worked. Last resort would be maintaining some sort of button list, but I'd rather not.
View Replies
View Related
Jan 20, 2014
I just started taking a Java class and i'm having problems with this code,
I'm trying to add up the 4 numbers have them print out on screen.
public class finalGrade
{
public static void main(String[] arg)
{
double pLp = 28.3; //Participation, lab work, and programming
[Code] .....
View Replies
View Related
May 16, 2014
how to access my rrmLogin from the web?
With JSP can do? How do it? or exist other way? or: [URL] ....
I tested (i need some configuration): [URL] .... but this method download the jar file (and other libraries) right? and the program act same as a Desktop app, right?
View Replies
View Related
Sep 29, 2014
I have created a java gui on Windows 7 with Eclipse EE, using a screen resolution of 1366 x 768. I used groups with specified boundaries. For example:
final Group g5_script_data = new Group(shell, SWT.BORDER_SOLID);
g5_script_data.setText("Current DB");
g5_script_data.setBounds(0, 0, 680, 380);
g5_script_data.setBackground(green);
The groups cover the whole screen.
However my colleague with a smaller resolution looses the far right of the screen.
As this is a proto-type and I'm new to Java I don't want to rework everything or convert it to say a grid layout until the proto-type is accepted and I can start from scratch with a real detailed design. It already has 6500 lines of source.
Just wondered what is my quickest/easiest way to get my app to display on a slightly smaller resolution. For sure it will not be anything silly. Something like 1280 x 768 to 1366 x 768 would do.
View Replies
View Related
Feb 7, 2014
I am trying to draw an image unto the screen, however, nothing appears...
Java Code:
private ImageIcon i = new ImageIcon("image.png");
private Image image;
...
image = i.getImage();
...
g.drawImage(image, (int)(x - r), (int)(y - r), null); mh_sh_highlight_all('java');
Am I doing it right? The program gives me no error, it's just that when I try to draw it, I see nothing.
View Replies
View Related
Apr 10, 2014
I have a program thats ran over a network and is multi-player. However whenever I fire any bullets they do not fire on the other clients screen. Here's the code
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
public class TankWar {
[Code] ....
View Replies
View Related
Jan 30, 2015
Haven't used java in a long long time and firstly need to know if its possible to build an app to replicate my ipad touch so that I can loop it between two different points on the screen. Friend recommended I got netbeans to get me started but wanted to ensure its possible before I get started.
View Replies
View Related
Feb 11, 2015
I had developed small GUI using swing group layout, which is nice to see on windows, but when I tried it on Linux the GUI look is varied. Then I set the GUI height and width by taking screen resolution, still it is varies the screen look. How I can make the GUI such that it looks the same on all screen resolutions.
View Replies
View Related
Sep 22, 2014
I am making a game and i am trying to have enemies spawn slight off the screen and randomly each time the game is run. I can get them to spawn randomly but i cant seem to get them off the screen properly ( when i do they take too long to enter the screen).
here is the code
for(int b = 0; b < GamePanel.enemy_amount; b++){
GamePanel.enemy.add(new Enemy((int)(Math.random() * 4000),(int)(Math.random() * 200)));
}
here is the width and height of the JFrame
setSize(1200, 800);
View Replies
View Related