Swing/AWT/SWT :: Retrieving Variables From Another Class?

May 19, 2014

This program should create a GUI that has 5 classes together on a grid layout. The problem that I am having is that the user input class has the input for kwh, hours, and gallons. I am having problems getting that information from the user input class to the totals class.

user input class:

package applianceutilitycalculator;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.*;

[code].....

The totals class should take the info from the kwh hours and gallons and do the math to get a total and display it in a JTextField(?).

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Retrieving Values From Property File That Matches Key

Aug 22, 2014

I have a properties file with a set of commands and their meanings (Command = the meaning). I Populated a jtree with the keys from the properties file, now when I click a node in the jtree (key) I want the value of that selected key to go in the panel that sits in my app next to the jtree.

View Replies View Related

Swing/AWT/SWT :: Null Pointer Exception When Retrieving Data From Table

Mar 31, 2015

I am trying to export data from a jtable to a pdf report but every time i try running the code it gives me this exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at GUI.QC_receiving_book.printButtonActionPerformed(QC_receiving_book.java:309)
at GUI.QC_receiving_book.access$600(QC_receiving_book.java:26)
at GUI.QC_receiving_book$7.actionPerformed(QC_receiving_book.java:165)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)

[Code] ....

I tried avoiding the null exception by using the if statement but it didn't work. The row I choose from the table is full meaning there are no empty attributes. and all the data are imported from a mysql database to the table as String so there can't be any casting errors.

This is the part of the source code with the problem and i will also post the printing method. I tried debugging the class and when stepping into the first if statement it opened the jTable.java file and pointed at the getSelectedRow() method and this sentence "variable information not available.source compiled without -g option"

private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(samplesTable.getSelectedRow() >= 0){
int row = samplesTable.getSelectedRow();
System.out.println(row);
for(int x=0;x<samplesTable.getColumnCount();x++){
String value = samplesTable.getModel().getValueAt(row, x).toString();

[Code] ....

View Replies View Related

Inheritance In Java - Child Class Get Copy Of Methods And Variables Of Parent Class?

Mar 1, 2015

Does child class gets a copy of the methods and variables of parent class?

public class test1 {
public static void main(String a[]) {
Child c = new Child();
c.print();

[Code] ....

why is the output 1?

View Replies View Related

Reading Variables Class To Class

Feb 3, 2014

I just want to be able to read type and weight in the Letter class I created (I created read out messages to check in the Letter class). I am able to read it with in the Mail class.

package org.mailprice.postage;
import java.util.Scanner;
public class Mail {
static Letter letter;

[code]....

View Replies View Related

Access To Variables In Another Class?

Oct 4, 2014

I will like to add to the questions about constructors and its this. I have a class A with a constructor, i have a class B which initialize the constructor. also i have a class C which needs a variable in class A but doesn't need to initialize the constructor of A. the question how do i access the variable of class A without initializing the constructor.

View Replies View Related

Accessing Variables Within A Class?

May 19, 2013

I wanna know which is the best way to access a variables within a class ...

Using direct access or using the variable accessor ...

Example :

public class Numbers{
        private int n1;
        private int n2;
     public void setN1(int n){
     n1 = n;

[Code] ....

View Replies View Related

Private Variables In Class / Constructor

Jan 7, 2014

When creating a class with a constructor, why does one have to create private variables (attributes) to be used as parameters by the object? The object's parameters will be set to be exactly equal to the private variables (attributes), so what is the point of having the private variables (attributes) Why are both private variables (attributes) and parameters needed when they are set to be equal each other anyway?

View Replies View Related

Post Integer Variables In Next Class

Jan 31, 2014

I write a small program. I want post my integer variables in the next class. Here a code(I wanna change answer color):

Main class(pagrindine.java):
import java.awt.*;
import javax.swing.*;
import java.awt.event.*; 
import javax.swing.event.*;
//Mokinio rinkinukas su skaiciofke kur gali keisti atsakymo spalva, pabandyti sukurti uzrasu knygute.
 
[code]....

So, I want to post variables r,g,b from class slideris.java in the pagrindiness.java.

View Replies View Related

Initialization Of Variables At Class Level

Feb 11, 2014

if I declare

class Example
{
int x=10;
......
}

It is not showing any error but when I declare

class Example
{
int x;
x=10;
............
}

it showing compile time error ....

View Replies View Related

Java Applet - Sharing Variables With Another Class

Mar 29, 2015

I have An Issue With My Java Applet. Im Trying To Share My Variables With Another Class, But Its Not Working.

Class 1

package com.Tobysmith10.game.main;
import java.applet.Applet;
import java.awt.Graphics;
public class Game extends Applet{
public void init(){
 setSize(850,480);
 public void paint(Graphics g){
 g.fillOval(x,y,20,20);
}
}

Class 2

package com.Tobysmith10.game.main;
import java.applet.Applet;
public class gameLoop extends Applet implements Runnable{
public int x, y;
public void run(){
while(true){
x = 100;
y = 100; 
}
}
}

So im sharing the x and y variables with the Class 1 , but I get yellow lines under it and when i run the program, it crashes, how do I get class 1 to recognize the variables from class 2 ?

View Replies View Related

Accessing Variables From Array Instance Of Class?

Jan 26, 2015

I am having some problem accessing variables from an array instance of a class. Heres what i have done;

In the main class:

Example obj[]= new Example[4];

In the main class constructor:

obj[0] = new Example(0);
obj[1] = new Example(1);
obj[2] = new Example(2);
obj[3] = new Example(3);

In the main update() method:

if(condition)
//update

In the Example class constructor:

private boolean change = false;

In the Example class update() method:

if(x >20)
change= true;

Now, i want to access the variable change from the main class, how do i do it? The 'condition' in the if statement is the condition of wether the change variable ia true or false. How do i access it?

View Replies View Related

Creating Instance Variables And Constructors For Map Class

Mar 27, 2014

I have to create an application that deals with maps.

I first have to create the instance variables for the class.

So very simply if my hashmap is going to consist of football clubs and players. Football clubs being a string value for the key and players being a set of strings for the values. How would I go about creating the instance variable in a class for this?

I can't seem to find anything that specifically deals with instance variables and constructors for maps.

View Replies View Related

How To Get Access From Variables In Super Class Or Subclass

Dec 2, 2014

how to get access from variables in a super class or a subclass. Here is what I got:

1) I have a super class that is in Jar file, I created a link in Eclipse, I know that the link is created correctly, I am going to concentrate just in one variable, so I don’t have to put all the code here firstName; in the super class(the one that is define in the path)

public class CommissionEmployee {
// Field descriptor #6 Ljava/lang/String;
private java.lang.String firstName;

in my class i have 6 argument constructor

View Replies View Related

Instance Variables Can Be Declared In Class Level Before Or After Use

Jun 3, 2014

From the tutorial:instance variables can be declared in class level before or after use.But the code below does not compile. Why?

Java Code:

public class MainApp {
i=5;
public static void main(String[] args) {
System.out.println("Hello World");
}
int i;
} mh_sh_highlight_all('java');

View Replies View Related

Swing/AWT/SWT :: How To Share Member Variables

Jul 10, 2014

I can understand basic concepts such as OOP, Threads, Events and GUI, I've coded a little but I've always had this bothering me:

Explaining by example:

public class X{
int x;
String y;
public static void main(String[] args){
x = 10;
y = "hello ";

[Code] ....

Okay, i'm pretty certain that code won't work, but I just want to show you conceptually, not actually care whether the code works or not. In case I wanted to get that code to work I should have probably used a Swing application to get a KeyListener in the first place, but I guess I know that, and if this was working, what would happen theoretically is, the code would run, initialize x to 10, and y to hello, then when a key is pressed, it will update x to 11 and y to hello world, I'm pretty sure that's what happens.

In this case, I used a inner class to update it's parent's members, I've seen this done before and I can vouch for the fact that it's a legitimate way to code a class.

Now in this example:

class X{
int x;
String y;
public int getX(){ return x; }
public String getY(){ return y; }

[Code] ....

So in this overly complicated example, i'm trying to share class X with both class Y and class Z, just that how to share the members of class X with the different classes without making a new instance of X. In the previous example, I could access the parent's members because the inner class was implicitly capable of accessing the parent's members. However in this case, If "Y" starts an instance of X, then how do I access it? because it's a side by side class not a hierarchy for me to access the parent's members.

View Replies View Related

Jtable And Updating Variables In Swing

Jan 21, 2015

I am working on a project in Eclipse, and it is my first time working with swing.I have the GUI setup the way that I like it, my hang-up is how to "update" the variables in the code as they are changed.The basics of the code is that I have several different String[] that will show up in a Jtable depending upon the input of the lists I have in the GUI.

in essence,
if list1==2 && list2==3
returnedarray = array1

I would like to have the returnedarray/Jtable be updated live as the lists are manipulated. So as soon as I change my list selections to...
list1==1 && list2==3

the code would shift to the proper array...
returnedarray = array2

If making the output update live isn't a possibility how would I code a button to update the input/output giving me the proper String[]?

View Replies View Related

Sorting Array Of Objects Based On One Of Class String Variables

Apr 8, 2014

I have a school assignment that involves me sorting an array of objects based on one of the class String variables. I am using as the title says a simple selection sort method. The problem I'm having is that when I run the program in debug mode, it never seems to enter the if statement in the inner loop. I would like to say I've tried a number of things to figure it out, but honestly I'm just stumped as to why it's not working.

Here is the code:

public static void sortTransactions(Transaction[] oTransaction){// This is the sorting method, obviously it's not done so it currently just prints to screen.
System.out.println("Successful call to sortTransaction()");
String min = "";
int curInd = 0;
Transaction[] temp = new Transaction[1];

[Code] ....

The output when I check to see if the array is sorted verifies that the array never does get sorted.

View Replies View Related

Setting All Variables In Class To Null Or 0 To Make A New Method To Clear Everything

Mar 31, 2014

I am very Java illiterate and I need to know how would i set all the variables in the first class to null or 0 to make a new method to clear everything.

import java.util.Arrays;
import java.util.Scanner;
public class studentMethods
{
private double totalScore;
private int count;

[Code] ....

View Replies View Related

Create A Class That Includes Three Pieces Of Information As Instance Variables

Oct 9, 2014

Creating a class. Specification are given as:

Create a class called Employee that includes three pieces of information as instance variables:

-Employee ID (string type)
-first name (string type) (default value 'John')
-last name (string type) (default value 'Smith') and
-monthly salary (type double).
-No argument constructor that initializes the three instance variables. The employee id should be generated using the following process:

The employee id should be a combination of first initial, last initial and a number starting from 10001 for the first employee and increasing by one for each employee. e.g. if John Smith is the first employee then its id will be JS10001 and if George Brown is the second employee then its id will be GB10002

-Provide get and set methods for each instance variable. The set method for monthly salary should ensure that its value remains positive - if an attempt is made to assign a negative value, leave the original value.

View Replies View Related

Servlets :: Thread Safety Should Not Use Any Variables Or Objects At Instance / Class Level

Jun 3, 2014

As web server has multiple threads to serve client requests in Thread Pool & to ensure Thread Safety we should not use any variables or Objects at Instance/Class level.But in case of Session Variable which one is the Best Practice as the Session object is used by all the requests to have the same Session ID.

My Code :

public class MyServlet extends HttpServlet {
private static Logger log = Logger.getLogger(ClientRegistrationServlet.class);
private HttpSession session; /* This is used at Instance Level*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

[code]....

View Replies View Related

Retrieving Text Off Of A Button?

Nov 16, 2014

I am trying to check to see if the button has anything on it.

Line 81 says incompatible types: JButton cannot be converted to String ')' expected ';' expected

package PA7;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;

[code]...

View Replies View Related

Retrieving Values Of Object

Aug 8, 2014

How do I retrieve values of an object?

public Software[] getSoftware(int index){
return software;}

The object is initialized and i get no errors when entering values .. but when i try to print by calling getSoftware I get :

[Ldd1318398project4.Software;@257f6796

View Replies View Related

Retrieving Values From A JTextField

Jan 18, 2015

I currently building a hotel reservation system, and I'm having issues with retrieving and setting other values from a JTextField.

What I'm trying to do is to retrieve the value that was inputted into a textfield, and then setting that value to a string in another class.

In here, I'm trying to retrieve values from the JTextField:

@Override
public void actionPerformed(ActionEvent event) {
GuestInfo gi = new GuestInfo();
if (event.getSource()==roomView)
{
roomViewFrame.setVisible(true);
roomViewFrame.setSize(1000, 600);

[Code] .....

View Replies View Related

JSF :: Retrieving Hidden Input

Jun 23, 2014

I have this code

<h:form id="theform">
<h:inputHidden id="user_id" value="3" />
<h:commandButton action="userprofile.xhtml?faces-redirect=true" value="Profile" />
</h:form>

How I can retrieve the value of user_id at page userprofile.xhtml?

View Replies View Related

Servlets :: Next Button And Retrieving Name Of JSPs

Feb 21, 2014

I want to have a button in my Jsp's labeled "next" that takes me to the next JSP in a certain order. Imagine a book: every time you click next you go to the next page.

Each page is a JSP that is named "page#" where # stands for the number (page1, page2,etc).

I was structuring my app this way: one controller,one controllerhelper,multiple JSPs.

The "next" button in the JSP's would always have the same name as not to overcode in my controllerhelper with too many options for the button that was pressed.

So my idea was to retrieve the name of the current JSP and work the string in order to add a number (page4 turns into page5) and forward it through a requestdispatcher.

That is the problem as I am not able to get the name of the current JSP since the url changes after the first page to the servlet url.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved