Using JFrame To Open Up Log In Or Out Windows For User - Unknown Variable Error
Jul 31, 2014
I am trying to use a JFrame to open up extra windows that will prompt the user the Log In or Out, but I am getting an error with one of my variables that writes to Excel. There is something wrong with the variable "sheet" contained in the "while(i <= 4)"
private void createLabel(WritableSheet sheet) throws WriteException
{
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
times = new WritableCellFormat(times10pt);
times.setWrap(true);
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
[Code] .....
View Replies
ADVERTISEMENT
Sep 2, 2014
I got stuck with the error "Unknown class" with the code that I copied from the book ...
import javax.swing.*;
class SwingDemo
{
// create a new JFrame container
JFrame MAIN_FRAME = new JFrame ("A Simple Swing Application");
// give the frame an initial size
MAIN_FRAME.setSize(275, 100);
// terminate the program when the user closes the application
MAIN_FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
[code]...
The error comes from lines 21 and 27.
21 MAIN_FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27 MAIN_FRAME.add(FIELD_LABEL);
I have tried to rewrite from scratch and still gets the same error.
View Replies
View Related
Jun 2, 2014
I'm making a tic tac toe program. Currently I have a welcome screen for my tic tac toe game, once the button is clicked I want the main game to open. I have created two FXML VBox windows created from JavaFX Scene Builder. I want to know how to close the welcome menu and launch the 2nd FXML window.
This 2nd FXML window will have it's own controller where the tic tac toe calculations will be held.
Here is the event listener on when the mouse action is performed on the button
@FXML
private void startGame(ActionEvent event) {
}
View Replies
View Related
May 4, 2014
There are a lot of variables in physics and it is easy to manipulate equations to find the unknown variable. Well, in my program I have the problem of determining which equation to solve for an unknown. You can see I have a timeF, timeI, time, distanceI, distanceF, distance...etc...variables. The way that I have written the code, it will scan for an empty() JTF and assign it as the unknown variable (not sure I can do it this way anymore). At that point, the value is passed into the correct calculation method to process the equation based on a series of case statements in each method...
I know the button arrays I have set up will process correctly in the checkJTF method...and I will need to account for that...but right now my focus is on getting the program to properly calculate the kinematics equations and display the result in the JPanel.
public class PhysicsFrame extends JFrame {
//Kinematic variables
private static float distanceI, distanceF, velocityI, velocityF,
velocityAverage, acceleration, time, timeF, timeI, result;
//Power variables
[Code] .....
View Replies
View Related
Oct 7, 2014
int x = 10;
do{
System.out.print("value of x : " + x );
x++;
System.out.print("");
}while( x + x == 22 );
When i put x+x==22 than it gives 2 values of x which are 10 and 11, they are wrong but when i put any other value like x+x==24 it just shows 1 value which is 10. I am not able to understand what mistake is there. I have been searching it for past whole month but didn't got any reason.
View Replies
View Related
Nov 24, 2014
My program compiles and runs ok how ever when i open my Jinternal frame and click on one of the JLabels i get a error on the Cmd ther error reads as follows
************************ ERROR **************************
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at JLabelAssignment.mouseClicked(JLabelAssignment.jav a:429)
at java.awt.Component.processMouseEvent(Component.jav a:6508)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3320)
[code]...
View Replies
View Related
Nov 30, 2014
I made UpdateInmateDisplayer a Singleton so that I could access it from the private class ButtonHandler. It works to display the first inmate's number on the screen but when I close out the window and click the Book Inmate button in CurInmatesDisplayer again, it only shows a blank window. I've tried adding the components again from the ButtonHandler in CurInmatesDisplayer but it doesn't work.
View Replies
View Related
May 16, 2014
I am using Jframe to do keylistener to detect what key i type. so example when i type A it will return A and so on for other key. But what i really want is using textarea in jsp and have this similar or same code in servlet. Below are the code in JFrame
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JTextField;
[Code] .....
View Replies
View Related
Feb 2, 2014
In one jframe i have insert one jfilechooser but when i open in second time jfilechooser when i want close...don't close.
When I close jframe i want destroy memory of jfilechooser... How to do???
For to close jframe i write:
jframe.dispose();
but don't to do nothing....
View Replies
View Related
Jan 17, 2015
Can I add a variable to Windows PATH from java code?
View Replies
View Related
Aug 9, 2014
I'm working on a problem where I have to use the FileInputStream to opens a file that contains the name of a user's favorite book and then displays it.
If the file doesn't exist, then I prompt for the book title and write it to the file using FileOutputStream. This is what I have so far but I'm lost because if I put a file that exists in line 8 then it closes, but if I don't and the user puts their favorite book nothing happens. Or, as far as I can tell nothing does.
import java.io.*;
class DisplayBook {
public static void main(String[] args)
[code]....
View Replies
View Related
Jul 29, 2014
What's wrong with my Java program? When I open it using appletviewer, the applet opens but stays blank and an error message appears in Terminal.
Java Code:
import java.applet.*;
import java.awt.*;
public class DemoColor extends Applet
{
Font littleFont = new Font("Helvetica", Font.ITALIC, 6);
public void paint(Graphics gr)
[Code] ....
Error Message:
Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue
at java.awt.Color.testColorValueRange(Color.java:310)
at java.awt.Color.<init>(Color.java:395)
at java.awt.Color.<init>(Color.java:369)
at DemoColor.paint(DemoColor.java:24)
[Code] ....
HTML file:
<HTML>
<APPLET CODE="DemoColor.class" WIDTH = 420 HEIGHT = 300>
</APPLET>
</HTML>
View Replies
View Related
Oct 9, 2014
I would like to pass a variable I have in my main to my JFrame. In my main I calculate which pictures I should show in my JFrame. Is it possible to make objects of these pictures in my main class and use them in my JFrame? something like my code below.
public class JFrameTesting {
public static void main(String[] args) {
Image ImageVariable = Toolkit.getDefaultToolkit().getImage("C:1.jpg");
MyJFrame f = new MyJFrame();
f.setTitle("Drawing Graphics in Frames");
[code]....
View Replies
View Related
Apr 3, 2015
Right so I have my ItemsPage Jframe Class and I'm trying to pass my TotalPrice variable to my CashPay so I can calculate the change. CashPrice runs and works but when I try run ItemsPage it does nothing I don't even get errors. I tried to remove that small section of trying to pass the variable to CashPay and it worked perfectly so I 100% know that's the problem. This section "public ItemsPage() { Pounds = ""; //super();
Scanner sc = new Scanner(System.in);
CashPay sendTotalPrice = new CashPay();
//System.out.println("Enter your amount");
TotalPrice = sc.nextDouble();
sendTotalPrice.printTotalPrice(TotalPrice);
"
Here is complete code for both classes, I'm using GUI builder.
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
[code].....
View Replies
View Related
Jun 24, 2014
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
public class Racquet {
private static final int WIDTH = 60;
private static final int HEIGHT = 20;
[code]....
The problem arises at the portion of the code that says
private int Y = game.getHeight() - 70;
I am not actually getting any compiler errors, but when I try to run the program, the command prompt pops up with this message:
Exception in thread "main" java.lang.NullPointerException
at Racquet.<init>(Racquet.java:19)
at Game.<init>(Game.java:10)
at Game.main(game.java:58)
What I want to do is make it so a GUI object that I created moves with the screen when I change the height. If I change it to private int Y = 330; the program works just fine.
View Replies
View Related
Jul 29, 2014
What I'm trying to do is show a loginscreen. After logging in it should show another contentpane with actual content.
This is my main class:
public class Project extends JFrame
{
public static void main(String[] args)
{
JFrame frame = new Project ();
JPanel paneel = new Paneel ();
frame.setSize (800, 600);
[Code] ....
The compiler gives me an error when I try to refer to "frame". What I've tried to do is refer to frame by using
Project.frame but it still gives me the same error. The compiler shows the message that it cannot find "frame" in class Project, but that's exactly where it is!
Is there a simple way to make this work? I've read about threads and loops but they don't seem the most basic solution. Maybe there's a way to get the current frame so I can use that?
View Replies
View Related
Feb 21, 2015
I know what the error means but I don't think initializing the variable will make my code work as intended so I'm having a little dilemna here... here's the code and I'll highlight the part that is said to be not initialized:
Java Code:
import java.util.Scanner;
public class ItemCost {
public static void main (String []args){
int i=1,item=1,e=1, f=1, g=1;
int items, d ;
double gst, qst, subt, Tot = 1, PriceItems ;
[Code] ....
So I'm supposed to get the following output :
Java Code:
Please input the amount of items bought 2
Please input the price of the item 1 1
Please input the price of the item 2 2
Please input the rate of GST in % 20
Please input the rate of QST in % 18 mh_sh_highlight_all('java');
HOWEVER my program doesn't seem to add input of item 1, and 2 if I initialize subt= 0 initially. It'll only take the last value inputted in the loop. By the way, the increments are counters to count the amount of errors the user might input by accident ( or whatever). Some people have been pointing it out as useless but that's the only way I found it to work.
View Replies
View Related
Oct 12, 2014
I don't understand that the error occurs when I don't initialize the variable myPoint. Whereas, I initialize the variable myPoint after variable declaration and before place of error.
package enumeration;
import java.util.Random;
public class Craps {
[Code]....
When I initialize the variable myPoint to zero in its decleration, the error disappear. But why? I have already initialized the variable myPoint in default case before the line of error occured..
View Replies
View Related
Sep 16, 2014
Okay, so I know how to get user input and create a variable from the input, create a basic addition sum etc...
So I have this code:
package calc;
import java.util.Scanner;
class calc{
private static final double add = 0;
private static final double subtract = 0;
public static void main(String args[]){
[Code] .....
I'm basically trying to make it so that when the user enters tnum, tnum2, tnum3 and tnum4, their answer turns to the variable which has to be either true or false to make the boolean work. I don't know really how to do this. I want to make it so that if they enter yes, then that makes the boolean true and the numbers will multiply and create the answer variable. If they enter no then the boolean is false and it moves onto the next if statement. How can I do this?
View Replies
View Related
Feb 10, 2015
I am writing a program to store books (Book class) in volumes (Volume class). Within the main class (DemoVolume) I am doing a couple different things. I want to ask the user if they are creating a new array, if yes, I was to create a new array with a variable names assigned by the user. Is this possible? The reason is I want to allow the user to be able to search their library of volumes. If no, then the user will enter the book information and I will assign it to an array unassignedVolume that will contain individual books. I would also like to create book objects that are defined with the book name, if this is possible. I'm just messing around and trying to deepen my understanding of JAVA. My main issue is how to allow the user to title the volume (array variable).
import java.util.Scanner;
public class DemoVolume {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String [] volume, unassignedVolume;
Volume volumeOne = new Volume("JAVA", 3, volume);
[Code] ......
View Replies
View Related
Jun 27, 2014
I am getting an error stating that 'word cannot be resolved to a variable' pointing to my return value. Why? Should I make a default String value for word before my while loop or something, like
String word = " ";
?
String getItRight(){//make sure the user enters the password correctly
Scanner input = new Scanner(System.in);
boolean repeating = true;
while(repeating){
[Code] ....
View Replies
View Related
Jun 18, 2014
The error "cannot resolve to a variable". I get the error I just can't seem to fix the error.Presently I am working my way through the Oracle docs and that seems ok. Java for Dummies, Sams teach Yourself Java in 21 Days, plus my favorite Head First Java.
package tutorial;
import java.util.*;
public class HolidaySked {
BitSet sked;
public HolidaySked(){
sked = new BitSet (365);
int [] holiday = {1,15,50,148,185,246,281,
316,326,359};
for (int i = 0; i<holiday.length; i++){
addHoliday(holiday[i]);
[code]....
View Replies
View Related
Mar 31, 2014
Consider the following simple code:
public class Test {
private final int arg;
private final Runnable runnable1 = new Runnable() {
@Override
public void run() {
// No errors here, exactly as expected
System.out.println("ARG: " + arg);
[Code] ....
The java compiler (version 1.8.0-b132) produces the following error when compiling this code:
"Error:(14, 46) java: variable arg might not have been initialized"
Actually, I do not expect the error here.
Both declarations 'runnable1' and 'runnable2' are essentially the same: these are just Runnable objects accessing value of the 'arg' field (which is initialized in the constructor).
The only difference between the declarations is that 'runnable1' - is an old-fashion instantiation of Runnable, whereas 'runnable2' - is an instantiation of Runnable via a lambda expression.
View Replies
View Related
Mar 23, 2015
I'm getting this error, I definitely know that is my error trying to pass method/variable because when I commented received part of my code it ran and worked.
I get this error
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here are my 2 classes
Java Code:
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[Code] .....
View Replies
View Related
Feb 28, 2015
I want to use a try catch block, but I am not sure how to fix this problem:
int a;
try{
a = Integer.parseInt(A.getText());
}
catch (Exception e){
Output1.setText("Error");
}
//do someting with a here
The purpose of the try-catch is to catch blank input.The problem with this is that underneath the try - catch I get an error saying that the variable might not have been initialized. I know why this happens. I know I could initialize the varaible before the try - catch, but there is no default or null I can set an int as. If I initialized it as 0, the blank input will no longer be catched.how to make this problem disappear?
View Replies
View Related
Sep 14, 2014
I am trying to create this program I am pretty sure it is easy but I am making it difficult lol, it keeps giving me a error, it is saying cannot find symbol - variable keyboard, I don't think I have keyboard as a variable but I may be wrong.
double distancel = keyboard.nextdouble(); that is the specific line ....
import javax.swing.JOptionPane;
import java.io.File;
import java.util.Scanner;
//import java.util.totalInches;
//instance variables
public class Map{
public static void main(String[] args){
[Code] ....
View Replies
View Related