Swing/AWT/SWT :: Map KeyStrokes In ActionMap Using CardLayout In JApplet
Jan 14, 2014
I am developing a game where a player has to find a path in a maze. Right now the player can only click the buttons on the maze. I need an option to use the arrow keys.
I have picked up pieces from my code to illustrate my problem. Below is the code. If I call "AnyClass" in the "AppletClass" it works but when I call "MiddleClass" in the "AppletClass" and MiddleClass" calls "AnyClass" it does not work. In my project at www.hiredforoneday.com I call 4 panels in CardLayout before I call "AnyClass" which is the "Maze"
package keymapingincardlayout;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
[Code] .....
View Replies
ADVERTISEMENT
Mar 20, 2015
I have a stage,it has two layers scene, if user click the button,then change to another layer, and also can change back. It just like swing cardlayout. How can i implement cardlayout in JAVAFX?
View Replies
View Related
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
Jun 11, 2014
So I have basic java knowledge from 1st year of college and I wrote a program recently that sends keystrokes with the Robot class. Now I would like it to do the same but to send it to a window that isn't my active one.. I've searched and from what Ive found it seems like you cant do that in java, I need another language like C# (whick sux for me since i dont know any other then java).. Is this true? If not how would i send something to notepad for example while it is not the active window?
View Replies
View Related
Jan 1, 2014
In my Java 2D game, two tanks are controlled as follows:
Tank 1
- Move forward: UP arrow
- Adjust angle of movement: LEFT and RIGHT arrows
Tank 2
- Move forward: W key
- Adjust angle of movement: A and D keys
It is possible to adjust the angle of a tank while it's moving forward (e.g., striking the left arrow or the right arrow while striking the up arrow). It's also possible to move both tanks forward simultaneously.
However, while one tank is moving forward and changing its angle (e.g., striking the up and the left/right key at the same time), the other tank is only able to move forward. That is to say, it cannot adjust its angle (e.g., striking W and A at the same time won't work, while the other tank is doing the same thing; the A key is ignored).
Why is that? Here's the relevant code:
In the Board class, that has most of the game logic:
Java Code:
while( game_is_running ) {
keysPressed1 = tank1.getKeys();
keysPressed2 = tank2.getKeys();
if(keysPressed1[0]==true)tank1.setAngle(tank1.getAngle()-3);
if(keysPressed1[1]==true)tank1.setAngle(tank1.getAngle()+3);
if(keysPressed1[2]==true){
[Code] .....
You will probably suggest I use Key Bindings, but is there a way to still use KeyListener and have all buttons work at the same time without errors?
View Replies
View Related
Jan 17, 2014
How do you use GridBagLayout and CardLayout together?
I'm trying to add these buttons to a panel, but it breaks the GridBagLayout, here's what is in the doc;
Java Code:
button = new JButton("Button 1");
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
[Code] .....
I'm trying to do:
Java Code:
JPanel m = new JPanel();
button = new JButton("Button 1");
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
m.add(button, c);
[Code] .....
However it reverts as though it's using flowlayout. What is it I'm missing?
View Replies
View Related
Jun 11, 2014
I've got a problem with my home made game. When I created it as a JFrame application it runs smoothly, but when I tried to convert it to a JApplet the graphic is "lagging". I can see the graphics blinking/flashing .....
Here is the code:
public class FallingBalls extends JApplet implements KeyListener,
ActionListener {
// VARIABLES //
boolean gameOver;
boolean win;
// Buttons
JButton start, pause, restart;
// Character "The Runner" (32px x 32 px)
[code]....
View Replies
View Related
Feb 6, 2014
I just created an applet that I want to call from a html file.The applet code looks like this (and works):
Java Code:
package jav12
import java.awt.*;
import javax.swing.*;
public class Welcome extends JApplet {
public Welcome(){
[code]...
When I click on the html file the content of the page is blocked and the applet isn't loaded. URL...
View Replies
View Related
Jun 12, 2014
I've got a problem with my applet when I run it in a browser (firefox mainly but nothing else is working neither). First of all, the program is "unsigned" according to firefox security system, but I don't think that's where to problem lies. When I start the applet (as an html application) it says:
AccessControlException
Then it says: Access denied ("java.io.FilePermission" "bla, bla, bla (img source on my harddrive)" "read")
How do I get this to work? This is the picture I'm trying to implement: [URL]...
View Replies
View Related
Feb 6, 2014
I just created an applet that I want to call from a html file.
The applet code looks like this (and works):
package jav12;
import java.awt.*;
import javax.swing.*;
public class Welcome extends JApplet {
public Welcome(){
}
public void init() {
getContentPane().add(new Label("Yessss it works",Label.CENTER));
[Code] ....
When I click on the html file the content of the page is blocked and the applet isn't loaded. What can I do to fix this. I think it has something to do with rights. This is a crosspost to JApplet content blocked
View Replies
View Related
Dec 16, 2014
I am trying to make a japplet that has open, zoom in and zoom out buttons for pictures. I am not sure how to go about an open button that will read the file. I have the picture url hard coded in the file to open but would like an open button with a file/folder dialogue.
This is what I have so far
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
[Code] ......
View Replies
View Related
Apr 15, 2014
I'm not exactly sure what the draw button is supposed to do specifically, all i know is that it is supposed to draw both rectangles and ovals. The problem I am having is that when ever I click Draw Rectangle, it draws rectangles jusst the way I want but when ever I click Draw Oval, the program keeps drawing rectangles. I've tried repaint and clearRect methods but I did not manage to get them to work. I'm not sure what the problem is right here, I just cannot get it to work. Is there anything you guys can see that might be causing this? It's always good to have a different person look at it then myself. Also, I'm trying to implement a boolean for draw oval but I don't know where to put the if then.
public void init() {
length = new JTextField(10);
width = new JTextField(10);
btnDraw = new JButton("Draw");
btnClear = new JButton("Clear");
btnDrawRectangle = new JButton("Draw Rectangle");
btnDrawOval = new JButton("Draw Oval");
[Code] .....
View Replies
View Related
Jul 7, 2014
So I'm trying to make an applet and I found that Thread.sleep() to simply delay is a bad idea.
I'm not sure how to use the Timer class to implement a same version of sleep() to delay 6 seconds. I am trying to do this in a for loop to delay before every loop. How can I implement this?
This code is after the init() method. For simplicity I didn't include. Assuming I did:
Timer t = new Timer(6000, null);
public void actionPerformed(ActionEvent e) {
try {
URL rsUrl = new URL("http://rscript.org/lookup.php?type=namecheck&name=" + n1);
BufferedReader br = new BufferedReader(new InputStreamReader(rsUrl.openStream()));
for (count = 0; count < maxCount; count++) {
[Code] ....
View Replies
View Related
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
View Related
Nov 6, 2013
This is what he wants: He wants us to prompt the user to input x values and y values (that will be entered into an array when clicking one of the two buttons (this one will say: Add point)). When they click the second button (draw lines), it should take all the points and draw a line that connects all the points together using a method that we write. In the method we have to call the paint method up which the lines will be drawn. The lines drawn should be touching every point added. It shouldn't have parameters. It will also use Graphics painter = getGraphics(); We can't use frames either.
I have everything up until the method understood.
How to write a method that will draw a line from points inputted that is called up in the action listener when the second button (draw lines) is pressed.
View Replies
View Related
Apr 10, 2014
I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,
1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
2) The problem may be to display the JDesktopPane or JInternalFrame.
My working Server Code extends withe JFrame..Java Code:
package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
[code]....
View Replies
View Related
Feb 16, 2014
I have a problem with progress bar implementation to my project. Let me explain it;
I have Jframe named GUI. Filled with 2 datechooser combo box and 1 Buton.
And i have a Swingworker class named "MySwingWorker" for my long running task just like this;
package exampleproject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
[code]....
Just i want add a progress bar for listening MySwingWorker's setProgress updates. When buton clicked swingworker should executed and progress bar should come to screen. I read many articles about that but not understand correctly. Because i am beginner in JAVA.
Question1: Should i (create new class) or (implement to current gui or swingworker class) for progressbar?
Question2: Should i fired progress bar first and execute swingworker from progressbar class? or should i execute swingworker first and fired progress bar later and how?
View Replies
View Related
Jul 26, 2014
Is it a good idea to use the factory design pattern for say if I needed to create four different JDialogs for the same parent frame?
factory design interface
package client;
public interface Dialog {
void getInstanceOf ();
void initComponents ();
}
One of the four JDialog class would look something like this without the comments.
package client;
import javax.swing.JDialog;
@SuppressWarnings("serial")
public class AddCustomerDialog extends JDialog implements Dialog{
public AddCustomerDialog () {
//Some stuff goes here to set the settings for JDialog instance
[code]....
Of course you would have your factory class
View Replies
View Related
Mar 19, 2014
I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the GUI update themselves with localized text from a ResourceBundle of the new locale.If there a simple way of achieving this without having to create an event model for all GUI pages?
View Replies
View Related
Apr 19, 2014
can we create web applications using swings? if yes how to create web app using swing?
View Replies
View Related
Jan 17, 2015
I have created a jtable with two columns so I need add checkboxes dynamically in to the first column.Bıt I couldn find something like add.How can do this.This is what I have so far
public CheckBoxes(){
table=new JTable(new TableModels());
TableColumnModel columnModel = null;
JCheckBox box;
for (int i = 0; i <2; i++) {
[Code] ....
View Replies
View Related
Dec 20, 2014
I've almost finished building an Editor in Java, but i'm a bit stuck on creating a JCheckBox that saves your credentials (as in password only) . I would like it to be on a JPanel under the password input box and above the Login and Register buttons.
Code:
Login.java (Main class for this problem)
[URL] ....
The main thing here is using GridLayout, which is what im currently working with but can't seem to get it under the password input box.. check: [URL] ....
View Replies
View Related
Mar 17, 2014
How to add combo box to swing ....
View Replies
View Related
Feb 12, 2014
how to open a GUI on top of another GUI? I have built a GUI and have a button that when pressed I want to open a new GUI which is another java application within the project, it seems pretty straight forward and I just need to insert 'new [name of application]()'
Button btnEdit = new Button(shell, SWT.NONE);
btnEdit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new edit();
}
});
btnEdit.setBounds(76, 10, 75, 25);
btnEdit.setText("Edit");
View Replies
View Related
Sep 13, 2014
What is the best way to run a Swing application on the web? Should I convert it to an applet or do something else?
View Replies
View Related
Jan 6, 2014
I find myself asking these two questions because I see them as relating. First question is; I always write
Java Code: f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mh_sh_highlight_all('java');
(where f is a JFrame object)
to set the close for the JFrame. What I don't get about this is what is going on in the parenthesis. I looked in the Java Documentation, and it says an int goes inside. In that case, I don't really get what the word JFrame is doing there. Overall, please explain what is inside the parenthesis of that line and why it has to be there.The second question is a generic question. I notice a lot of times an object will be created, and as its parameter, you will have to instantiate an object. an example would be
Java Code: Class f = new Class(new Object) mh_sh_highlight_all('java');
What does it mean when an object gets created inside of a new object? Why is putting Java Code: new Object mh_sh_highlight_all('java');
ever necessary when concerning the two parenthesis?
View Replies
View Related