Calling Another Class
Jun 14, 2014
So heres the code for one of my classes..
import java.awt.*;
import javax.swing.*;
public class Splash extends JPanel {
public void paint (Graphics g)
[code]....
Now, when i call it from a different class in the main method, like this:
new Splash();
View Replies
ADVERTISEMENT
May 28, 2014
Regarding the lifecycle of servlet , in headfirst servlet i can find :
You normally will NOT override the service() method, so the one from HttpServlet will run. The service() method figures out which HTTP method (GET, POST, etc.) is in the request, and invokes the matching doGet() or doPost() method. The doGet() and doPost() inside HttpServlet don’t do anything, so you have to override one or both. This thread dies (or is put back in a Container-managed pool) when service() completes.
How can I call the doGet method of the subclass from the superclass. i am not getting this .
View Replies
View Related
Aug 11, 2014
i am having a problem while calling a method..i am having a class
Java Code:
public class MySer implements Runnable {
public void getMessage(String msg)
{
...,
}..,
} mh_sh_highlight_all('java');
i use the above class in another class
[code]....
View Replies
View Related
May 20, 2015
In the process of creating a new class, I need to move my main method from the class SaveDate to the class DynamicTest. Below I have listed the code of both classes.The objective is to be able to run my program from the DynamicTest Class. I need understanding the process of moving my main method to a different class and creating an Object of a class and calling its method.
public class SaveData {
private static final Map<String, Object> myCachedTreeMap = new TreeMap<String, Object>();
public static final List<String> getLines(final String resourceParam, final Charset charset) throws IOException{
System.out.println("Please get: "+resourceParam);
if (myCachedTreeMap.containsKey(resourceParam) ) {
// Use the cached file, to prevent an additional read.
[Code] ......
View Replies
View Related
Aug 31, 2014
// Add range to Vehicle.
class Vehicle {
int passengers; // number of passengers
int fuelcap; // fuel capacity in gallons
int mpg; // fuel consumption in miles per gallon
// Display the range.
void range() {
System.out.println("Range is " + fuelcap * mpg);
[Code] ....
I'm compiling it in Eclipse and this continues to show in the console display
Minivan can carry 7. Exception in thread "main" java.lang.NoSuchMethodError: Vehicle.range()V
at AddMeth.main(AddMeth.java:34)
View Replies
View Related
Sep 15, 2014
I am calling a method from within a class like so:
xmlWriter.updateFile(environment, doc);
The class is xmlWriter & the method is updateFile
updateFile passes Environment environment (another class) and Document doc (document builder)
but I am unsure about it passing these through the parameters in the method call..is it correct?
Also underneath that method call for the update could I then do another method call for the export method of the file?
View Replies
View Related
Mar 24, 2014
I am having problem to call a method from another class using arrays. I already know how to call a method without using arrays but I am not sure how to pass parameters to the main method using arrays. I'd really appreciate any feedback or comments!This is what I have so far.
public class Customer123 {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
int x;
System.out.print("Total number of customers: ");
x = input.nextInt();
[code]....
View Replies
View Related
Mar 6, 2015
calling a method from one class to another.I have two classes. One called Vacation and another called VacationDriver.I am trying to input an int for addVac and have the value update to the numSold within the updateSales() method in Vacation. From there it should update and display in the v1.toString in the VacationDriver.
Vacation
import java.text.NumberFormat;
public class Vacation {
private String vacationName;
private int numSold;
private double priceEach;
[code]...
View Replies
View Related
Oct 27, 2014
I have a class for employees. This class has basic information for the employee but no real pay information. And 2 subclasses, one for employee's paid for hourly rates and one for those paid a yearly salary. Each subclass has their own pay() method, that calculates and returns their pay and extra fields relative to calculate that.
I'm just curious, if I do this and create an object for an hourly paid employee like so:
Object hourly1 = new HourlyEmployeeWilson("John Doe", "123 Tech Street",361961,"Human Resources", 0,12.50,50);
How can I utilize that classes public method of pay() to gather this instance (or hourly paid employee)'s pay? I've tried doing so via:
System.out.println(hourly1.pay());
But I get
DriverPayWilson.java:9: error: cannot find symbol
System.out.println(hourly1.pay());
^
symbol: method pay()
location: variable hourly1 of type Object
1 error
View Replies
View Related
Mar 13, 2014
So I just finished up my term project and have everything working but I wanted to make one slight adjustment to the code and Im not exactly sure what I'm doing wrong - it involves retrieving a set element from an array from a different class so to some what show what I have going on:
public class example1 {
private example2 Examp;
public example1() {
Examp = new example2();
} public void getArray() {
if(Var >= 10 && Var <= 20) {
[Code] ....
I have an if statement that looks at a sum of numbers, and predetermined upon the set of numbers I want it to output a message by calling the index number in the array and returning the string. I currently just have the message in the if statements but would be nicer to just pull them from a different class to keep it consolidated.
View Replies
View Related
May 7, 2015
Okay so my main problem is that i can't seem to initiate three objects in order for it to display like a recipt in a way. Here is the picture of what the out is suppose to look like : Here are all three files of code
public class IceStand {
//Defining the properties
private String Name;
private String location;
[Code] ...
Output looks like currently
Please enter name of Shaved Ice Stand:
People who love ice cream
Please enter your zip Code:
21236
Enter number of Small (press -1 to stop):
0
Enter numebr of Medium:
1
Enter number of Large:
1
PEOPLE WHO LOVE ICE CREAM
21236
//---//---~------
Price Total
View Replies
View Related
Apr 14, 2014
how we can call one class in multiple programs to reduce code redundancy
View Replies
View Related
Aug 20, 2014
I have a frame which I want to load an applet inside it. Here is the code i have in my main method:
MyApplet myApplet = new MyApplet();
myApplet.init();
myApplet.start();
javax.swing.JFrame window = new javax.swing.JFrame("myApplet");
window.setContentPane(myApplet);
window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
But I get an exception:
Quote
Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:169)
at MyApplet.init(MyApplet.java:78)
at Intro.main(Intro.java:68)
Java Result: 1
View Replies
View Related
Oct 30, 2014
I have a driver and a main program. How would I go along with calling the encode method to the driver class that I made so I can have the user inputs affected by the encode method?
Java Code:
public class ShiftEncoderDecoder
{
private int shift;
public ShiftEncoderDecoder(int shift)
{
setShift(shift);
}
public int getShift()
[Code] ....
View Replies
View Related
Nov 3, 2014
How should I call my findSmallest method in the main class.. Here is the code:
public class Tester {
public static void main(String[] args){
try {
BinaryTree<Integer> myTree2 = new BinaryTree<Integer>();
myTree2.insert(5);
myTree2.insert(2);
myTree2.insert(7);
[Code] ....
So the question is what kind of parameter I should pass in myTree2.findSmallest()??? Here is my findSmallest method..
public E findSmallest(Node<E> parent){
if(parent.left.left == null){
E returnValue = parent.left.data;
parent.left = parent.left.right;
return returnValue;
} else {
return findSmallest(parent.left);
}
}
View Replies
View Related
Dec 30, 2014
I have two classes involved in this portion. CheckIn_Search
(class #1) is my main UI and I am collecting search information from the user in a jPanel form. When they click "Search" it passes the search criteria to a method that contacts a web service and gets the results. These results are passed to coSearchResults
(class #2) that opens a jFrame and jTable (in modal format, over the main window created by CheckIn_Search.
The user selects a row in the table and that selection data is passed back to coSearchResults to populate a new jPanel form. When the data is passed from coSearchResults, I want to close its window, hide the first jPanel in CheckIn_Search and make the second jPanel visible. To accomplish this, I created a method in CheckIn_Search that simply hides/shows the panels (it will do more later).
I instantiate and call the method in CoSearchResults as part of the button click event. The problem is, it doesn't work. The panels are unaffected and there are no errors. I've put in break-points and it goes into the method.. Here is the coSearch_Results code.
Here is am retrieving the jtable row id and using the first value in the row to get the data from the table model as there is more data than what is displayed in the table. I'm sending that whole row of data to the method that changes visibility.
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
// TODO add your handling code here:
int rowNum = jTable1.getSelectedRow();
String coNum = jTable1.getValueAt(rowNum,0).toString();
String[] text;
[code]....
View Replies
View Related
May 2, 2014
I've used Netbeans IDE to create a simple Swing JFrame container, class NewJFrame.
NewJFrame calls another JFrame with dialog in it. Problem is there is an endless call made to it. Here's the issue relevant piece of code:
//Code for calling class
package p;
public class NewJFrame extends javax.swing.JFrame implements ActionListener {
.........
public NewJFrame() {
initComponents(); //IDE auto generated code for binding
[Code] ....
I searched but i cannot understand why run class is getting called multiple times. I have attached the screen prints for both the screens. 2nd screen print(of called class) is very shallow since screen was blinking unstopped due to multiple calls, but i have attached a faint image of it.
View Replies
View Related
Oct 23, 2014
I am trying to call a private method to another method that are located in the same class.
I am trying to call prepareString to the encode method below.
Java Code:
public class ShiftEncoderDecoder
private String prepareString(String plainText)
{
String preparedString = "";
for(int i = 0 ; i < plainText.length();i++)
if(Character.isAlphabetic(plainText.charAt(i)))
[Code] .....
View Replies
View Related
Apr 23, 2014
i am creating a desktop application. In this application, firstly there is a log in form. Now, i want to display the another form on the same window i.e by removing log in form a new form..
View Replies
View Related
Jul 16, 2014
Using JPA 2.1, I have been trying without luck to call a function that returns a REF CURSOR containing RECORD TYPES. Is there a way of doing this?
One Example of trying:
Query query = em.createNativeQuery("select my_package.my_function from dual");
Object a = query.getSingleResult();
I have also tried to use the StoredProcedureQuery though this does not look like it can return the functions value.
Produced
org.springframework.orm.jpa.JpaSystemException: No Dialect mapping for JDBC type: -10;
nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -10
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:244)
[Code] ....
View Replies
View Related
Mar 25, 2014
I am calling a jsp page from my servlet using the requestdispatcher.forward(myjsp.jsp) method. myjsp.jsp is creating a new thread which is parallely processing along with the servlet. The issue is that the jsp page is not displayed until the servlet finishes its execution, although the new thread is created by jsp and is executing in parallel. How do we have the jsp page displayed even when the servlet is executing.
View Replies
View Related
Feb 12, 2015
I just wanted to ask that when we invoke a function by passing certain arguments in it ,so for instance I have certain variables like a,b and c with some values assigned to them,so when I invoke a function like func(a*b , 8, c+a) where the function func accepts parameters like func(int x,int y,int z) ,so is there any order of evaluation of expressions defined like the value of c+d would be evaluated first and then assigned to variable z ,because in C we have sequence points and since comma when acting like a separator is not a sequence point so any of the expression can be executed first ,so basically is there any sequence in which the function arguments are assigned to the parameters of the function or any relation with the stack implementation.
Even in C ,the printf starts executing its expressions from right to left so basically in why does it happen there when comma is a separator in a function argument.
View Replies
View Related
Jan 26, 2014
The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.
The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.
Java Code:
package plant.nursery;
import java.util.ArrayList;
import java.util.Scanner;
/**Class to create a plant for a nursery.
public class PlantNursery
[code]....
View Replies
View Related
Oct 23, 2014
I need to get the string encodedString from the method encode able to be used in the decode method.
Java Code:
public String encode(String plainText) {
int prepareString;
int shiftChar;
String preparedString2 = prepareString(plainText);
String encodedString = "";
for(int c = 0 ; c < preparedString2.length();c++)
[Code] ....
View Replies
View Related
Aug 8, 2014
I have a line code like this one:
String result = someHeavyMethod();
and I need to add this logic: "if the method doesn't finish within 10 seconds, cancel it and let me continue with the rest of the program".
View Replies
View Related
Apr 8, 2014
I need to create an applet that displays a grid of command buttons which I have done. I then need to create a new class that draws a silly picture of an alien, which I have also done. Where I am completely stuck and confused, is that I do not know how to get the drawing into the applet. My code is below. I really do not fully understand why this is not working or how to get it working.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MartianGame extends JApplet implements ActionListener {
DrawMartian aMartian = new DrawMartian();
DrawJupiterian aJupiterian = new DrawJupiterian();
[Code] .....
View Replies
View Related