How To Set Color When Space Is Pressed
Apr 11, 2014
The title says it all and i'm a fairly new java programmer but here is the code:
package TestVersion;
import java.awt.Color;
import java.awt.Graphics;
[Code]......
I think i need a variable or something oh and here is the 2 other classes, the keylistener one:
package TestVersion;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
[Code].....
View Replies
ADVERTISEMENT
Oct 29, 2014
I have a filechooser that works how it should and if anyone enters anything with a dot that isnt .xml it shows an invalid file name message. However when I dont choose a file and press cancel it still says that because when my boolean hits false it's the first thing it hits in that section of code.
if(!writeSuccess)
{
//display output messages in JOptionPane
JOptionPane.showMessageDialog(null,"Error, file name invalid", "Error", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null,"Export successful", "Success", JOptionPane.INFORMATION_MESSAGE);
//close the form
me.dispose();
}
If I want it to just close down without it saying anything is there sort of if statement I could do that would prevent this? But if it is an invalid file name it will still show that message?
View Replies
View Related
Jun 10, 2014
No problem setting background color for layouts, e.g. bdrPn.setBackground(new Background((new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))));
But neither of the following are working for me, running JavaFX 8 on latest OS-X
scene = new Scene(bdrPn, winW, winH, Color.BLACK);
scene.setFill(Color.BLACK);
scene.setFill() worked fine for previous versions of JavaFX.
View Replies
View Related
Oct 20, 2014
I've just started working on a program and i'm already having difficulties with the program. I can't get the background color to change from the basic gray color. Maybe you can tell me what i'm doing wrong.
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.*;
import java.lang.Object;
import java.awt.Color;
public class FrameDemo{
public static void main(String args[]){
Toolkit toolkit = Toolkit.getDefaultToolkit ();
[Code]...
also if theres any way to shorten up what I have there, that would be great.
View Replies
View Related
Nov 24, 2009
If I want to read from file the word "red" And then the following is not the right way like in the code ,, How to set the Color name
File inputFile = new File ("C:\input.txt");
Scanner scan = new Scanner (inputFile);
String RedColor=scan.nextLine();
Color backColor = new Color(redColor);
View Replies
View Related
Aug 21, 2014
I am very much new to Java. I have just started learning event handling. Currently I am learning about Key Events. And am learning by doing. Well that is how one could learn anything in fact. I want to write a program in which the currently loaded image in the panel of a frame changes upon a key press say "Enter" or any other key.
View Replies
View Related
Apr 17, 2015
I have this swing code here:
//dark elixir
Panel panel_4 = new Panel();
config.add(panel_4);
JLabel del = new JLabel("Starting DE: ");
panel_4.add(del);
[code]...
It all displays well etc but if I change the value of one of the fields then I'm not allowed to change the JCombox field anymore.
View Replies
View Related
Mar 15, 2015
I am able to update the array holding the items but I don't know how to refresh the JList to include all the new items in the array.
Code for GUI:
import java.awt.ScrollPane;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ListView extends JFrame{
HobbyList stuff = new HobbyList();
[Code] .....
View Replies
View Related
Dec 4, 2014
Ok, so I am trying to learn about JFrames and JPanels. I have figured out buttons, layouts, etc. What im having trouble with is accessing the label object from the ButtonHandler class since it is static and I need my JLabel to be non-static so that it can change. Basically, I want JLabel to change to a pre-determined text string once a button is pressed. Here's what I have so far
package makewindow;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
[code]....
View Replies
View Related
Apr 7, 2014
I have a class that implements JComponent and draw a rectangle and if a key pressed(for example UP) I want to draw it up, and then when down key pressed to draw it down... But I want not only to disappear, but somehow to move, so the user can see the rectangle moving...
View Replies
View Related
Dec 27, 2014
I have a VBox with 20 buttons and I have this style applied (menu.css) (only for VBox wrapper):
.button:focused {
-fx-background-color: #0768A9;
-fx-text-fill: #FFFFFF;
}
But when I pressed other button outside the VBox the style disappears, because the other button get the focus.
How I can do to keep the last button pressed with a custom style? (Only for buttons containing the VBox).
View Replies
View Related
Mar 19, 2015
Okay, gotta be able to move the image when a key is pressed. When I test it, the image moves, but leaves the old image behind.
package Game;
import java.awt.Component;
import javax.swing.JOptionPane;
public class Game
{
private Grid grid; //holds the grid used to store and display images
private int userRow; //keep track of which row the user-controlled image appears in
private int msElapsed; //keep track of the total amount of milliseconds that have elapsed since the start of the game
[Code] ....
Here is what I was given on instructions:
Complete the handleKeyPress method. Write the following line of code in the handleKeyPress method to check for a key press:
int key = grid.checkLastKeyPressed();
If the user pressed the up arrow (key == 38), move the user's image up one row (unless the user is already in the top row). Likewise, if the user pressed the down arrow (key == 40), move the user's image down one row (unless the user is already in the bottom row). Either way, make sure to update userRow.
Movement of the image can be accomplished by changing the value of userRow. Study how the initial image is displayed in the game constructor, then
Set the current image location to null
Update userRow to the new location and,
Set the image in the new value of userRow.
You should be able to move the user image up and down, and you should be prevented from moving the image off the screen.
View Replies
View Related
Apr 11, 2014
I want to run a few things in my main when a JButton is pressed but can't work out the best way to do it. Here's the code in the main.
public static void main(String[] args) throws FileNotFoundException, ParseException, InterruptedException{
Map m = new Map("defaultMap");
GameLogic g = new GameLogic("defaultMap");
GodsEyeView gev = new GodsEyeView(g, m);
gev.initialRun();
//Want to run this when a button is pressed.
HumanUser h = new HumanUser(g);
playerGUI gui = new playerGUI(h);
gui.run();
gev.run();
}
View Replies
View Related
May 6, 2014
The goal is to desplays circles (max of 30) of fixed radius = 20, with the rightmost circle drawn in blue and left most circle in red and the rest are in white. The center is determined by the location of the point where the mouse is pressed. the number of circles is equivalent to number of mouse has been pressed_ the circles will be drawn only when you push the "draw" button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JPanel;
public class CirclePanel extends JPanel {
private final int WIDTH = 500, HEIGHT = 300;
private final int RDIUS = 20;
private final int MAX = 30;
[code]...
View Replies
View Related
May 7, 2015
a code that will add 1 to a variable and store it anytime key "p" is pressed on the keyboardKeep in mind
Here's what i have....
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner kin = new Scanner (System.in);
int pa, ma;
[Code]...
View Replies
View Related
Jul 26, 2014
I cant apply my knowledge of the switch to modify this program.
What i need is that the program runs the same but i can press q to stop the program and it will continue in a loop otherwise. repeating the same process i.e displaying the characters entered until q is pressed.
How do i do it? I think i need to make use of do and while but how to apply those in this case.
View Replies
View Related
Jan 16, 2015
I am trying to align the core/middle side color of a cube, index 4, with the bottom middle color of the same side, index 7. (Each side has values 0-8 where 0 - is the top left corner, 1 is the top mid corner, 2 is the top right corner, 3 is the middle left corner, etc).
In addition to lining up those two colors, I am also making sure that the neighbor color of index 7(the color that it is attached), in this case the bottom color, matches with the top core/middle color. I will attach some pictures and a print out to show what I am talking about...
However, in my code when I am trying to align all of these up together, it does not go into the while loop. Each of the loops essentially is trying to get a match of same color with index 4 and 7, as well as making sure that index 7's neighbor color (the bottom color, in this case) matches with the top color.
Here is what I have tried:
private void alignSideColor(){//make the bottom colors neighbor match with a middle side value and rotate it to the top, for the top cross
if(cube.bottom.square[1].charAt(0) == topColor){
while(cube.front.square[7].charAt(0) != frontColor && cube.bottom.square[1].charAt(0) != topColor){
rotateBottomClockwise(1);
System.out.println("Trying to align side color...");
[Code] .....
The print out of the ELSE IF is:
alignment is: W-G and tops: R-R
NOW ITS ALIGNED
even though the sides, index 4 and 7, are NOT aligned with each other
I have also tried the same thing but with out the 2nd condition in each while loop, and although is DOES enter the while loop, it does not perform correctly -- index 4 and 7 WILL have matches colors, but it does not check to see if index 7's neighbor matches with the top color.
Here is how it prints out
** ** ** G7 B6 Y1 ** ** **//this portion is the back of the cube
** ** ** R6 W5 O4 ** ** **
** ** ** R3 W2 O1 ** ** **
B3 G4 Y9 W9 O8 Y7 W3 B4 G9//this portion is the left, top, and right of the cube
B2 G5 R8 W4 R5 Y6 O2 B5 G8
O7 W8 R9 B7 B8 B9 R1 R4 R7
** ** ** O3 O6 O9 ** ** **//this portion is the front of the cube
** ** ** Y2 Y5 Y8 ** ** **
** ** ** B1 G6 W7 ** ** **
** ** ** Y3 Y4 G1 ** ** **//this portion is the bottom the cube
** ** ** R2 O5 G2 ** ** **
** ** ** W1 W6 G3 ** ** **
Here is the cube showing the top, left and front side
Here is the left and bottom side. As you can see index 4, G5 -- yes that is a 5 lol -- does not have the same color as index 7, W8.
I need to rotate the bottom until W8 is aligned with a middle white value. An examples of a neighbor is: W8-R2
View Replies
View Related
May 4, 2014
I am quite new to developing Applets in java. I recently made an applet that will play a particular sound whenever a button is pressed. The sound files are placed in the same directory as the applet class file and i access them by using
AudioClip clip=getAudioClip(getCodeBase(),"A.wav").
The Applet runs fine in the appletviewer but whenever I try to open it using any browser like Chrome,IE,Firefox the applet loads but sound isn't played. I checked the java console and it showed
"java.security.AccessControlException: access denied ".
My questions are:
1. How do I allow the applet to get access to those files?
2. When the Applet is running from the local file system why CAN NOT I access those resources via getCodeBase() ???
3. I googled and found that I can sign a JAR and that can have full access to the computer. But how do I create a JAR from an applet (which has no Main method) while it asks me to point to the main class in the manifest?
View Replies
View Related
Feb 12, 2014
In c++, I'm aware that you can use the ignore function to ignore numbers after space, but in string how do I ignore a number after space is found for instance, "109 33" how would I ignore 33?
View Replies
View Related
Jan 19, 2015
I have an assessment for college, the part of my code that im struggling with is the part where the user enter their first name followed by a space and then their second name. I m using ---------------fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " ); ------------- to capture this. the issue is if the user only enter 1 name I need to output an error. the issue is I cant find a way to tell if the user entered a second name. This is what I have so far:
public void makename() {
// makes an inputbox to ask their name
fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " );
//separates the first and second name into 2 strings in order to make the username
[code]....
The problem is it accepts anything I type in without causing an error. What should I type in to stop this? ive tried anything but I cant find a way to tell if a surname has been entered or not.
View Replies
View Related
Apr 2, 2014
Here is the question I'm having trouble with:
Write a program that reads a list of characters:
eg.ubccdddwfreshawbgtiijhktrocbfgrtwghdddguppgrkitt. etc.
inputted from the keyboard one character at a time starting with a vowel (The vowels are a, e, i, o, and u) until a blank {spacebar} character is issued. You do not press enter after each character. Any other sequence should return an error message and a way of entering it correctly.
Having read in the list (or during the reading of the list) the program is to find the longest continuous occurrence of consonants, outputting the vowels between which this occurs and the length of this string of consonants.
{In the example above, the output would be 13ou}
Check for input errors and respond accordingly.
I have done most of it, the problem being that I don't know how to end the scan with a space so that I don't have to press enter. I have done the bit that finds the biggest amount of consonants in a row. (I'm writing in netbeans)
View Replies
View Related
Dec 8, 2014
I have been trying to space out output on a Java console window so that I have three columns with 6 rows of data from three different arrays. The code I have so far outputs the data with no problem however the spacing between the columns is uneven. My loop so far is made up as follows
for (int i = 0; i < printVotes.length; i++) {
System.out.println(printNames[i] + "
" + printVotes[i] + "
" + printPrecent[i] + "%");
}
As you can see I have been manually adding the space between each element of the array but this means that the space between each element is different because the size of each element is different if work out a loop that works out an even amount of space between the elements and then print this along with the elements ....
View Replies
View Related
Mar 27, 2014
I have eight panels that are one above the other and are the full width of the frame.
I would like to hide some of them some of the time and then "bring them back".
If I use panel1.setVisible(false) panel1 will disappear but then all the panels below it move up to take panel1's place.
I don't want that to happen. I want just a blank area where panel1 was.
Is there a way to do that?
View Replies
View Related
Mar 30, 2014
I want to cut my string from space char but i am getting exception....
Java Code:
import java.util.Scanner;
import java.util.StringTokenizer;
public class NameSurname {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String s0,s1=null,s2 = null,s3=null;
s0=sc.next();
[Code] ....
Console:
Lionel andres messi
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(Unknown Source)
at java.util.StringTokenizer.nextToken(Unknown Source)
at com.parikshak.NameSurname.main(NameSurname.java:15) mh_sh_highlight_all('java');
I/p -O/p:
my s0=Lionel andres Messi
And I want to break it as soon as i find space and save it in s1,s2 and s3
s1=Lionel
s2=andres
s3=messi
View Replies
View Related
Feb 10, 2015
I am working on my homework, and everything is fine. But I was wondering if I can fix one thing. basically it prompt from a user for a text file name and save the content as an array. some part of my code is here:
public class arraysort{
static BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
System.out.print("Enter the first name of the file: ");
String input = kb.readLine();
int[] firstArray = readFile(input);
firstArray = bubbleSort(firstArray);
View Replies
View Related
Mar 7, 2015
Java Code:
public synchronized boolean isHit (FilledRect missile) {
for (int col = 0; col < aliens[0].length; col++) {
for (int row = 0; row < aliens.length; row++) {
if (aliens[row][col]!= null && aliens[row][col].overlaps (missile)) {
aliens[row][col] = null;
return true;
}
return false;
}
}
} mh_sh_highlight_all('java');
And I get an error saying that it cannot find symbol method overlaps. So is there something wrong that I am doing?
View Replies
View Related