Importing classes to help applets - professionals
I am creating a applet that calls a additional .class that acts as a gatewat between the applet and a servlet(applet -> class -> servlet)
Inside the applet how I can make the 'import' statement for a file that is in the same directory of the applet????
Just typing import myclass; doesnt work
"expected '.' "
import Myclass;
^
There must have some kind of java.localdir.myclass
or something
Similar Messages
-
How do I obtain and import classes so that I can reuse them? For example there is a Person class that I want to reuse http://www.dcs.shef.ac.uk/~guy/java/lancs/Person.html and a Date class. How do I get a copy so that I can import it into my java program? I know this is a fairly straight forward question for anyone who is comfortable using Java. But for a beginner who grew up learning C++ I�m a little lost. Any help would be greatly appreciated. Also, I�m using Eclipse as my java editor/runtime environment. Thank you.
You have to find a copy of the .class file (or the Java source file and compile it to a .class file) and place the .class file in a directory that's accessible when Java executes. One way of doing that is to list the directory on the classpath, when you execute Java:
java -classpath <absolute path to directory> classfileName -
Importing classes... HELP!!!
I'm using JBuilder Enterprise Edition...
I open a .java file to edit and recompile to test my edit...
However I keep getting errors that classes imported in the ,java file do not exist...
I know they do, because I copied them locally to the folder where all the filess I need are located...
The .java files that compile into .class files are read-only (there are over 100 of them)
I've pulled them from a server to my local machine...
Even if I check them out in Visual Source Safe, I still get errors that the imported classes in the source code do not exist...
how do I fix this issue?Looks like I had a copy of JBuilder installed after all. So I selected Project-> Project Properties select the Paths tab then the Required Libraries tab (lower tab), hit the add button, then hit the new button. Fill in the library name and select project to hold the library. Then search your disk for the jar or the directory that contains your classes. Then hit OK a few times.
-
Working applet pacman needs to become class in bigger applet
But now I get freaky errors!!
I had pacman working as an applet then extended (another applet ) it, with working random action and change color buttons.
Everything fine but now I need 4 pacmen and thus the existing pacman applet needs to become a class !!!
I can't get it done, please help me !
I have this thus far...
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Autopacman extends Applet implements ActionListener
boolean Packleur1;
boolean Packleur2;
boolean Packleur3;
boolean Packleur4;
boolean Packleur5;
boolean Packleur6;
int klikken = 1;
public void init(){
pacmanPiet = new pacman();
Button kleur = new Button("Kleur veranderen");
kleur.addActionListener(this);
add( kleur );
public void paint(Graphics g){
g.setColor( Color.black);
g.drawLine( 0, 34, 600, 34 );
g.setColor( Color.yellow);
if( klikken == 1 )
{g.setColor(Color.yellow);}
if( klikken == 2 )
{g.setColor(Color.red);}
if( klikken == 3 )
{g.setColor(Color.blue);}
if( klikken == 4 )
{g.setColor(Color.black);}
if( klikken == 5 )
{g.setColor(Color.green);}
if( klikken == 6 )
{g.setColor(Color.white);}
g.draw(pacmanPiet); //teken de pacman voor het eerst
pacmanPiet.setWaardes( 200, 200, 50, 50, 5, 345 );
public void actionPerformed(ActionEvent e){
String str = e.getActionCommand();
if( str.equals("Kleur veranderen")){klikken++;}
if(klikken == 7)
{klikken = 1;}
if( str.equals("Random actie") ){ //Die stomme random functie
int i = (int)(Math.random() * 17);
switch(i){
case 1: case 7 : case 11: case 15 : str = "omlaag"; break;
case 2: case 8 : case 12: case 16 : str = "omhoog"; break;
case 3: case 9 : case 13: case 17 : str = "links"; break;
case 4: case 10 : case 14: case 0 :str = "rechts"; break;
case 5: str = "harder"; break;
case 6: str = "zachter"; break;}
if( str.equals("harder") ){ stap = stap + stapVerander;} //stap wordt 10 groter
if( str.equals("zachter") ){ stap = stap - stapVerander;} //stap wordt 10 kleiner
if( stap < 0){stap = 1;} //Stapgrootte wordt nooit negatief of nul
if( str.equals("links") ){ x -= stap; //linksknop laat pacman links kijken en bewegen
angleA = 185;
angleB = 345;}
if( str.equals("rechts") ){ x += stap; //rechtsknop laat pacman rechts kijken en bewegen
angleA = 5;
angleB = 345;}
if( str.equals("omhoog") ){ y -= stap; //omhoogknop laat pacman omhoog kijken en bewegen
angleA = 95;
angleB = 345;}
if( str.equals("omlaag") ){ y += stap; //omlaagknop laat pacman omlaag kijken en bewegen
angleA = 275;
angleB = 345;}
if( x <= 0){ x = 0;} // houdt de pacman tegen als hij links/rechts wil verdwijnen
if( x > 550){ x = 550;}
if( y <= 35){ y = 35;} // houdt de pacman tegen als hij boven/onder wil verdwijnen
if( y > 550){ y = 550;}
repaint(); // zet de pacman opnieuw op het canvas
public class Pacman extends Applet implements ActionListener
int x = 200, y = 200; //beginpositie pacman
int width = 50, height = 50; //formaat pacman
int stap = 20; //standaard stapgrootte
int stapVerander = 10; //stapgrootte wijziging
int angleA = 5; //beginhoeken pacman
int angleB = 345;
public void init(){
Button links = new Button("links"); //knoppen worden gemaakt en gelabeld
Button rechts = new Button("rechts");
Button omhoog = new Button("omhoog");
Button omlaag = new Button("omlaag");
Button harder = new Button("harder");
Button zachter = new Button("zachter");
links.addActionListener(this); //action events worden aan knoppen gekoppeld
rechts.addActionListener(this);
omhoog.addActionListener(this);
omlaag.addActionListener(this);
harder.addActionListener(this);
zachter.addActionListener(this);
add( links ); //knoppen worden op canvas gezet
add( rechts );
add( omhoog );
add( omlaag );
add( harder );
add( zachter );
public void paint(Graphics g){
g.tekenPac(this.x, this.y, this.width, this.height, this.angleA, this.angleB); //teken de pacman voor het eerst
void setWaardes ( int x, int y, int width, int height, int angleA, int angleB)
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.angleA = angleA;
this.angleB = angleB;
public void actionPerformed(ActionEvent e){
String str = e.getActionCommand();
if( str.equals("harder") ){ stap = stap + stapVerander;} //stap wordt 10 groter
if( str.equals("zachter") ){ stap = stap - stapVerander;} //stap wordt 10 kleiner
if( stap < 0){stap = 1;} //Stapgrootte wordt nooit negatief of nul
if( str.equals("links") ){ x -= stap; //linksknop laat pacman links kijken en bewegen
angleA = 185;
angleB = 345;}
if( str.equals("rechts") ){ x += stap; //rechtsknop laat pacman rechts kijken en bewegen
angleA = 5;
angleB = 345;}
if( str.equals("omhoog") ){ y -= stap; //omhoogknop laat pacman omhoog kijken en bewegen
angleA = 95;
angleB = 345;}
if( str.equals("omlaag") ){ y += stap; //omlaagknop laat pacman omlaag kijken en bewegen
angleA = 275;
angleB = 345;}
if( x <= 0){ x = 0;} // houdt de pacman tegen als hij links/rechts wil verdwijnen
if( x > 550){ x = 550;}
if( y <= 35){ y = 35;} // houdt de pacman tegen als hij boven/onder wil verdwijnen
if( y > 550){ y = 550;}
repaint(); // zet de pacman opnieuw op het canvasI get this error : Class or Interface expected .
I now have this ; please anyone?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Autopacman extends Applet implements ActionListener
int x;
int y;
int width;
int height;
int angleA;
int angleB;
int stap;
boolean Packleur1;
boolean Packleur2;
boolean Packleur3;
boolean Packleur4;
boolean Packleur5;
boolean Packleur6;
Pacman pacmanPiet;
int klikken = 1;
public void init(){
pacmanPiet = new pacman();
Button kleur = new Button("Kleur veranderen");
kleur.addActionListener(this);
add( kleur );
public void paint(Graphics g){
g.setColor( Color.black);
g.drawLine( 0, 34, 600, 34 );
g.setColor( Color.yellow);
if( klikken == 1 )
{g.setColor(Color.yellow);}
if( klikken == 2 )
{g.setColor(Color.red);}
if( klikken == 3 )
{g.setColor(Color.blue);}
if( klikken == 4 )
{g.setColor(Color.black);}
if( klikken == 5 )
{g.setColor(Color.green);}
if( klikken == 6 )
{g.setColor(Color.white);}
g.draw(pacmanPiet); //teken de pacman voor het eerst
pacmanPiet.setWaardes( 200, 200, 50, 50, 5, 345 );
public void actionPerformed(ActionEvent e){
String str = e.getActionCommand();
if( str.equals("Kleur veranderen")){klikken++;}
if(klikken == 7)
{klikken = 1;}
if( str.equals("Random actie") ){ //Die stomme random functie
int i = (int)(Math.random() * 17);
switch(i){
case 1: case 7 : case 11: case 15 : str = "omlaag"; break;
case 2: case 8 : case 12: case 16 : str = "omhoog"; break;
case 3: case 9 : case 13: case 17 : str = "links"; break;
case 4: case 10 : case 14: case 0 :str = "rechts"; break;
case 5: str = "harder"; break;
case 6: str = "zachter"; break;}
if( str.equals("harder") ){ stap = stap + stapVerander;} //stap wordt 10 groter
if( str.equals("zachter") ){ stap = stap - stapVerander;} //stap wordt 10 kleiner
if( stap < 0){stap = 1;} //Stapgrootte wordt nooit negatief of nul
if( str.equals("links") ){ x -= stap; //linksknop laat pacman links kijken en bewegen
angleA = 185;
angleB = 345;}
if( str.equals("rechts") ){ x += stap; //rechtsknop laat pacman rechts kijken en bewegen
angleA = 5;
angleB = 345;}
if( str.equals("omhoog") ){ y -= stap; //omhoogknop laat pacman omhoog kijken en bewegen
angleA = 95;
angleB = 345;}
if( str.equals("omlaag") ){ y += stap; //omlaagknop laat pacman omlaag kijken en bewegen
angleA = 275;
angleB = 345;}
if( x <= 0){ x = 0;} // houdt de pacman tegen als hij links/rechts wil verdwijnen
if( x > 550){ x = 550;}
if( y <= 35){ y = 35;} // houdt de pacman tegen als hij boven/onder wil verdwijnen
if( y > 550){ y = 550;}
repaint(); // zet de pacman opnieuw op het canvas
if( str.equals("harder") ){ stap = stap + stapVerander;} //stap wordt 10 groter
if( str.equals("zachter") ){ stap = stap - stapVerander;} //stap wordt 10 kleiner
if( stap < 0){stap = 1;} //Stapgrootte wordt nooit negatief of nul
if( str.equals("links") ){ x -= stap; //linksknop laat pacman links kijken en bewegen
angleA = 185;
angleB = 345;}
if( str.equals("rechts") ){ x += stap; //rechtsknop laat pacman rechts kijken en bewegen
angleA = 5;
angleB = 345;}
if( str.equals("omhoog") ){ y -= stap; //omhoogknop laat pacman omhoog kijken en bewegen
angleA = 95;
angleB = 345;}
if( str.equals("omlaag") ){ y += stap; //omlaagknop laat pacman omlaag kijken en bewegen
angleA = 275;
angleB = 345;}
if( x <= 0){ x = 0;} // houdt de pacman tegen als hij links/rechts wil verdwijnen
if( x > 550){ x = 550;}
if( y <= 35){ y = 35;} // houdt de pacman tegen als hij boven/onder wil verdwijnen
if( y > 550){ y = 550;}
repaint(); // zet de pacman opnieuw op het canvas
public class Pacman extends Applet
int x = 200, y = 200; //beginpositie pacman
int width = 50, height = 50; //formaat pacman
int stap = 20; //standaard stapgrootte
int stapVerander = 10; //stapgrootte wijziging
int angleA = 5; //beginhoeken pacman
int angleB = 345;
public void paint(Graphics g){
g.tekenPac(this.x, this.y, this.width, this.height, this.angleA, this.angleB); //teken de pacman voor het eerst
void setWaardes ( int x, int y, int width, int height, int angleA, int angleB)
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.angleA = angleA;
this.angleB = angleB;
} -
I was reading the tutorial on importing class's. This is what
I read
Importing classes
To reference a class in another script, you must prefix the
class name with the class's package path. The combination of a
class's name and its package path is the class's fully qualified
class name. If a class resides in a top-level classpath
directory--not in a subdirectory in the classpath directory--then
its fully qualified class name is its class name.
To specify package paths, use dot (.) notation to separate
package directory names. Package paths are hierarchical, where each
dot represents a nested directory. For example, suppose you create
a class named Data that resides in a com/xyzzycorporation/ package
in your classpath. To create an instance of that class, you could
specify the fully qualified class name, as shown in the following
example:
var dataInstance = new com.xyzzycorporation.Data();
My Question is about com/xyzzycorporation/ . would the full
class parth be c:/com/xyzzycorporation/ . Why do they never state
the drive letter when teaching about directories.Because there is no need. you don't need to reference the
drive letter.
Here's the basic jist of what they are saying....
Single Class File...
If you create your own custom class and want to use it in
your flash file, save it into the same directory as the fla file
and call the classes constructor. By default flash will look inside
the folder where the fla resides in for the class files if it
cannot find it inside the default directory.
Multiple Class Files - 1 Project (often referred to as
packages)
Use your qualified domain name but backwards.....
my domain is www.sd-dezign.com so if I was going to include a
package of utility class files in my document I would do the
following
Create a folder in the same folder with my fla name it com
and inside that a folder called sddezign and inside that utils and
all my as files would be in there...the folder structure might look
like this....
myfile.fla
com
>sddezign
>>utils
>>>box.as
>>>circle.as
To call the constructor for each class, I have two options.
The first which is by far the easiest looks like this
In whatever frame you need to call that class constructor
include "com.sddezign.utils.*";
var myBox:Box = new Box();
The second method requires more typing and can get tedious
var myBox = new com.sddezign.utils.Box();
Hope this helps you a bit better. -
Not allowed to import classes without package names?
Hi,
I have a few questions on Packages and importing?
1. Is the following true that it is illegal to import classes in the same package as the current class, will this cause a comilation error? If this is the case where in the Java Language specification is this actually written as I could not find it?
2. This has probably been answered by question 1 but if I have 2 classes in the same package and if I import 1 of the classes into the other class, is it illegal to import it by just using the class name and not the package name as well, ie
if the package name is ie.tcd
and the 2 class names are exp1.class and exp2.class, can I do this in class 2
package ie.tcd;
import exp1;
public class exp2 {
3. Is it illegal to import classes that are not explicitly part of any package or must a class be part of a package to be imported. I read somewhere that while this was always illegal it is only after jdk 1.4.2 that this is being enforced? If this is the case where in the Java Language specification is this actually written as I could not find it either?
Thanks very much for any help,
JohnWas just also wondering, 1 other thing, I am looking
at someone elses code they have 2 classes (Class A
and Class B) in the same package (pkg). The person
imports class A into B:
package pkg;
import A;
public class B {
Is this legal code (or was it ever)?Not if A is really in pkg.A. If there is an A in the unnamed package it was legal, or at least it was understood by the compiler, and now it isn't (to both).
Can you import or is there a point in importing a class in the same
package?Only by naming the package in the import statement. If the current and the import statement are in the same package the import is redundant.
If there is a point would you import just be
using the class name (this would be illegal after jdk
1.4) or should you use the whole package name even
though it is in the package anyways?As I understand it you must always use the whole package name in imports. -
Compilation Error for import classes not found in generated Proxy Class
Hi,
We are generating java classes for the COM dll using JCOM com2java compiler.
We are getting a compilation error for import class not found when compiling the
generated Proxy java source code. It can't find the com.bea.jcom.Dispatch class that
the generated Proxy java source code extends. It also can't find com.bea.jcom.Variant
or com.bea.jcom.Param. These are interfaces or data types or classes used by COM
library.
I added weblogic.jar to my class path and the only Dispatch class i found inside
the weblogic.jar is com.linar.jintegra.Dispatch;
We have com objects for which we want to develop an EJB client to interface with
the COM object using JCOM with Native Mode disabled.
Any help on the compilation error..I tried changing the extends for Dispatch to com.linar.jintegra.Dispatch
but the other errors are still there.
To begin with, I think the generated code should not refer to any of the COM data
types.
Any help please.
Thank you in advance,
Regards,
Rahul Srivastava
[email protected]Hi,
I resolved the other errors by changing all references from com.bea.jcom.Variant
etc to com.linar.jintegra.class name..all were present under the com.linar.jintegra
package.
Thank you all anyways,
Regards,
rahul
"Rahul Srivastava" <[email protected]> wrote:
>
Hi,
We are generating java classes for the COM dll using JCOM com2java compiler.
We are getting a compilation error for import class not found when compiling
the
generated Proxy java source code. It can't find the com.bea.jcom.Dispatch
class that
the generated Proxy java source code extends. It also can't find com.bea.jcom.Variant
or com.bea.jcom.Param. These are interfaces or data types or classes used
by COM
library.
I added weblogic.jar to my class path and the only Dispatch class i found
inside
the weblogic.jar is com.linar.jintegra.Dispatch;
We have com objects for which we want to develop an EJB client to interface
with
the COM object using JCOM with Native Mode disabled.
Any help on the compilation error..I tried changing the extends for Dispatch
to com.linar.jintegra.Dispatch
but the other errors are still there.
To begin with, I think the generated code should not refer to any of the
COM data
types.
Any help please.
Thank you in advance,
Regards,
Rahul Srivastava
[email protected] -
Problem importing classes and beans
Hey there. Im having one major fustrating problem! When I code supporting classes and beans for my JSPs I get a code 500 internal server error when trying to import (via <%@ page import="class" %> and <jsp:useBean/>) Im storing my classes and beans in the WEB-INF folder and the calling JSPs are located in /ROOT/tests/8/jsp.jsp. Im using the following to import a class or bean:
<%@ import="aClass" %>
Seen as tho its in the WEB-INF folder I won't have to explicitly refer to where the class is located, just the class name.
I never had this problem when I was using my hosting service. Its only on my localhost server in which I get the Internal Server error.
Help appreciated, thx.
PS: Im quite new to JSP/Java Servlet.import (via <%@ page import="class" %> and
<jsp:useBean/>) Im storing my classes and beans in the
WEB-INF folder try put your class file in WEB-INF/classes.
or first put bean in the package, like WEB-INF/classes/packagename/beanclass
in jsp page:
<jsp:useBean id="Mybean" class="packagename.beanclass" scope="request" />
Question: is /ROOT a context entry in your server.xml?
Which JSP Container (version) you use? Maybe your localhost server's set up is different with your hosting. -
Hi, new to 3D, doubt in importing class
hi all,
i m new to JAVA 3D, i currrently hv a simple example source which i try to compile it, it just can't, saying that class not found, but i m sure i hv download and install the JAVA 3D for DirectX 1.3.1, also i hv the following code
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Label;
import java.awt.GraphicsConfiguration;
// below having importing class problem
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;can anyone guide me, thank youThat is the way I understand it. Here is the information from the documentation.
The version of the Export utility must be equal to the version of either the source or target database, whichever is earlier.
For example, to create an export file for an import into a later release database, use a version of the Export utility that equals the source database. Conversely, to create an export file for an import into an earlier release database, use a version of the Export utility that equals the version of the target database.
In general, you can use the Export utility from any Oracle8 release to export from an Oracle9i server and create an Oracle8 export file.
Then further down is this handy table:
Table 21-5 Using Different Releases of Export and Import
Export from Import to Use Export Release Use Import Release
10.1.0 9.0.2 9.0.2 9.0.2
So, that is the way I understand this. I have not done this, but this is how I undertand it to work.
Please correct me if I am wrong.
Thanks
Dean -
Importing classes in Jsdk 1.4.2
Hi,
I have two swing applications that run perfectly well when compiled and run. But then I am trying to include these two programs as two tabbed panes in a third program.
I try to import classes from the other two programs using a simple import statement. But when I compile it the compiler return an error statement.
I tried putting a package line in both the programs and tried importing it as a package in the third one and it says invalid package name.
Can anybody help.
Thanks in advance.OK here is the code. This is a example code from the book Java2 from scratch
First file
PortfoilioTotalsPanel.java
// Import the packages used by this class
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
// PortfolioTotalsPanel Class
public class PortfolioTotalsPanel extends JPanel
// Define the dark green color
public final static Color darkGreen = new Color( 0, 150, 40 );
// Create our labels
JLabel lblDollarChange = new JLabel( "Dollar Change:", JLabel.CENTER );
JLabel lblPercentChange = new JLabel( "Percent Change:", JLabel.CENTER );
// Constructor
public PortfolioTotalsPanel()
// Set the layout manager
setLayout( new GridLayout( 2, 1 ) );
// Add the labels to the JPanel
add( lblDollarChange );
add( lblPercentChange );
// setDollarChange( fDollarChange )
// Set the Dollar Change label to the dollar amount in fDollarChange
public void setDollarChange( Float fDollarChange )
// Set color based off of value
if( fDollarChange.floatValue() > 0 )
// Green for positive
lblDollarChange.setForeground( darkGreen );
else if( fDollarChange.floatValue() < 0 )
// Red for negative
lblDollarChange.setForeground( Color.red );
else
// Black for no change
lblDollarChange.setForeground( Color.black );
// Set the label text
lblDollarChange.setText( "Dollar Change: $" + fDollarChange.toString() );
// setPercentChange( fPercentChange )
// Set the Percent Change label to the percent in fDollarChange
public void setPercentChange( Float fPercentChange )
// Set color based off of value
if( fPercentChange.floatValue() > 0 )
// Green for positive
lblPercentChange.setForeground( darkGreen );
else if( fPercentChange.floatValue() < 0 )
// Red for negative
lblPercentChange.setForeground( Color.red );
else
// Black for no change
lblPercentChange.setForeground( Color.black );
// Set the label text
lblPercentChange.setText( "Percent Change: " + fPercentChange.toString() + "%" );
// Main application entry point into this class
public static void main( String[] args )
// Create a JFrame object
JFrame frame = new JFrame( "Portfolio Totals" );
// Create an PortfolioTotalsPanel Object
PortfolioTotalsPanel app = new PortfolioTotalsPanel();
// Set the values of the labels
app.setDollarChange( new Float( "-150.50" ) );
app.setPercentChange( new Float( "15" ) );
// Add our PortfolioTotalsPanel Object to the JFrame
frame.getContentPane().add( app, BorderLayout.CENTER );
// Resize our JFrame
frame.setSize( 600, 100 );
// Make our JFrame visible
frame.setVisible( true );
// Create a window listener to close our application when we
// close our application
frame.addWindowListener
new WindowAdapter()
public void windowClosing( WindowEvent e )
System.exit( 0 );
Second Program
// ===========================================================================
// File: StockTablePanel.java
// Description: Sample file for Java 2 From Scratch
// ===========================================================================
// Import the libraries this application will use
import javax.swing.JTable;
import javax.swing.table.*;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
// Main application class: StockTablePanel
public class StockTablePanel extends JPanel
// Create a new Stock Table Model object
StockTableModel stockTableModel = new StockTableModel();
// Create a new JTable and associate it with the StockTableModel
JTable stockTable = new JTable( stockTableModel );
// Constructor
public StockTablePanel()
// Set the size of the table
stockTable.setPreferredScrollableViewportSize( new Dimension(620, 350) );
// Set the column widths for the table
TableColumn column = null;
for (int i = 0; i < 5; i++)
column = stockTable.getColumnModel().getColumn( i );
column.setPreferredWidth( stockTableModel.getColumnWidth( i ) );
// Create a scroll pane and add the stock table to it
JScrollPane scrollPane = new JScrollPane( stockTable );
// Add the scroll pane to our panel
add( scrollPane, BorderLayout.CENTER );
// float getDollarChange()
// Computes the total dollar change for the current portfolio
public float getDollarChange()
// Create a variable to hold the total change for all stocks
float fTotal = 0;
// Loop through all rows in the table
for( int i=0; i<stockTable.getRowCount(); i++ )
// Retrieve the dollar change for this stock
Float f = ( Float )stockTable.getValueAt( i, 10 );
// Add that value to our total
fTotal = fTotal + f.floatValue();
// Return the total value
return fTotal;
// float getPercentChange()
// Computes the total percentage change for the current portfolio
public float getPercentChange()
// Create a couple variables to hold the total the user spent
// on the stocks and the current value of those stocks
float fMoneySpent = 0;
float fMoneyWorth = 0;
// Loop through all rows in the table
for( int i=0; i<stockTable.getRowCount(); i++ )
// Extract some pertinent information for the computations
Float fLastSale = ( Float )stockTable.getValueAt( i, 2 );
Float fNumberOfShares = ( Float )stockTable.getValueAt( i, 6 );
Float fPricePaidPerShare = ( Float )stockTable.getValueAt( i, 7 );
// Add the amount of money the user spent on this stock
// to the total spent
fMoneySpent += fNumberOfShares.floatValue() * fPricePaidPerShare.floatValue();
// Add the value of this stock to the total value of the
// stock
fMoneyWorth += fNumberOfShares.floatValue() * fLastSale.floatValue();
// Compute the percentage change:
// TotalValue/TotalSpent * 100% - 100%
float fPercentChange = ( (fMoneyWorth / fMoneySpent) * 100 ) - 100;
// Return the percentage change
return fPercentChange;
// Main entry point into the StockTableApplication class
public static void main( String[] args )
// Create a frame to hold us and set its title
JFrame frame = new JFrame( "StockTablePanel Application" );
// Create an instance of our stock table panel
StockTablePanel stockTablePanel = new StockTablePanel();
// Add our tab panel to the frame
frame.getContentPane().add( stockTablePanel, BorderLayout.CENTER );
// Resize the frame
frame.setSize(640, 480);
// Make the windows visible
frame.setVisible( true );
// Set up a window listener to close the application window as soon as
// the application window closes
frame.addWindowListener
new WindowAdapter()
public void windowClosing( WindowEvent e )
System.exit( 0 );
// Table Model Class - holds all of our row and column information
class StockTableModel extends AbstractTableModel
// Create the columns for the table
final String[] strArrayColumnNames =
"Sym",
"Company Name",
"Last",
"Hi",
"Lo",
"Vol",
"#Shares",
"$Shares",
"Total",
"%Change",
"$Change"
// Create the rows for the table - hard coded for now!!
final Object[][] obArrayData =
// Row One
"SAMS", // Symbol
"Sams Publishing", // Company Name
new Float( 10 ), // Last Sale
new Float( 12 ), // High
new Float( 8 ), // Low
new Double( 2000000 ), // Volume
new Float( 100 ), // Number of Shares Owned
new Float( 7.5 ), // Purchase price per share
new Float( 1000 ), // Total Holdings
new Float( 33 ), // Percent change (increase!)
new Float( 250 ) // Dollar change
// Row Two
"Good", // Symbol
"Good Company", // Company Name
new Float( 50 ), // Last Sale
new Float( 52 ), // High
new Float( 45 ), // Low
new Double( 4000000 ), // Volume
new Float( 100 ), // Number of Shares Owned
new Float( 30 ), // Purchase price per share
new Float( 5000 ), // Total Holdings
new Float( 33 ), // Percent change (increase!)
new Float( 250 ) // Dollar change
// Row Three
"BAD", // Symbol
"Bad Company", // Company Name
new Float( 20 ), // Last Sale
new Float( 22 ), // High
new Float( 18 ), // Low
new Double( 2000000 ), // Volume
new Float( 500 ), // Number of Shares Owned
new Float( 50 ), // Purchase price per share
new Float( 10000 ), // Total Holdings
new Float( -60 ), // Percent change (increase!)
new Float( -25000 ) // Dollar change
// Return the number of columns in the table
public int getColumnCount()
return strArrayColumnNames.length;
// Return the number of rows in the table
public int getRowCount()
return obArrayData.length;
// Get the column name from the strArrayColumnNames array for the "col"-th
// item
public String getColumnName( int col )
return strArrayColumnNames[col];
// Return the value, in the form of an Object, from the obArrayData object
// array at position (row, col)
public Object getValueAt( int row, int col )
// We will compute columns 8, 9, and 10, so if the column number is
// below eight, we can just return it without computing or retrieving
// anything.
if( col < 8 )
return obArrayData[row][col];
// Retrive the necessary values from the object array to compute all
// of the remaining columns
Float fLastSale = ( Float )obArrayData[row][2];
Float fNumberOfShares = ( Float )obArrayData[row][6];
Float fPurchasePrice = ( Float )obArrayData[row][7];
switch( col )
// Total Holdings = Last Sale(2) * Number of Shares Owned(6)
case 8:
// Build a new Float object with the product of the two
Float fTotal = new Float
// Note, these have to be converted to type "float" to
// perform the multiplication
fLastSale.floatValue() * fNumberOfShares.floatValue()
// Return the result
return( fTotal );
// Percent change =
// (Last Sale Price (2) / Purchase Price (7)) * 100% - 100 %
case 9:
Float fPercentChange = new Float
((fLastSale.floatValue() / fPurchasePrice.floatValue ()) * 100) - 100
return fPercentChange;
// Dollar Change =
// LastSale*NumberOfShares - PurchasePrice * NumberOfShares
case 10:
Float fDollarChange = new Float
( fLastSale.floatValue() * fNumberOfShares.floatValue() )
( fPurchasePrice.floatValue() * fNumberOfShares.floatValue() )
return fDollarChange;
// We have included every case so far, but in case we add another
// column and forget about it, let's just return its value
default:
return obArrayData[row][col];
// Return the class type, in the form of a Class, for the c-th column in
// the first (0-th indexed) element of the obArrayData object array
public Class getColumnClass( int c )
return getValueAt(0, c).getClass();
// Return true if the "col"-th column of the table is editable, false
// otherwise. The following columns are editable:
// Cell Description
// 0 Symbol
// 6 Number of Shares Owned
// 7 Purchase Price per Share
public boolean isCellEditable(int row, int col)
// Check the column number
if( col == 0 || col == 6 || col == 7 )
return true;
else
return false;
// Set the value of the (row, col) element of the obArrayData to value
public void setValueAt(Object value, int row, int col)
// Symbol
if( col == 0 )
// We need a string value - we can convert any
// value to a string, so just assign it
obArrayData[row][col] = value;
// Number of Shares owned
else if( col == 6 )
// We need a number - either float or int
obArrayData[row][col] = new Float( getNumberString( value.toString() ) );
// Purchase Price per share
else if( col == 7 )
// We need a float
obArrayData[row][col] = new Float( getNumberString( value.toString() ) );
// Cell is not editable
else
return;
// Notify our parent of the change
fireTableCellUpdated(row, col);
// String getNumberString( String str )
// Read through str and return a new string with the numbers and decimal
// points contained in str
public String getNumberString( String str )
// Get str as a character array
char[] strSource = str.toCharArray();
// Create a buffer to copy the results into
char[] strNumbers = new char[strSource.length];
int nNumbersIndex = 0;
// Boolean to ensure we only have one decimal value
// in our number
boolean bFoundDecimal = false;
// Loop through all values of str
for( int i=0; i<strSource.length; i++ )
// Check for a digit or decimal point
if( Character.isDigit( strSource[i] ) )
strNumbers[nNumbersIndex++] = strSource;
else if( strSource[i] == '.' && !bFoundDecimal )
// Append the character to the String
strNumbers[nNumbersIndex++] = strSource[i];
// Note that we found the decimal value
bFoundDecimal = true;
// Build a new string to return to our caller
String strReturn = new String( strNumbers, 0, nNumbersIndex );
// Return our string
return strReturn;
// Return the column width of the column at index nCol
public int getColumnWidth( int nCol )
switch( nCol )
case 0:
case 2:
case 3:
case 4:
case 6:
case 7:
case 9:
return 50;
case 1:
return 125;
default:
return 75;
Third one that imports the previous two programs Classes
// Import the packages used by this class
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
// Import our other components
import StockTablePanel;
import PortfolioTotalsPanel;
// StockTableTabPanel
public class StockTableTabPanel extends JPanel implements TableModelListener
// Create our panels
StockTablePanel stockTablePanel = new StockTablePanel();
PortfolioTotalsPanel portfolioTotalsPanel = new PortfolioTotalsPanel();
// Constructor
public StockTableTabPanel()
// Set our layout
setLayout( new BorderLayout() );
// Initialize the portfolio panel
updatePortfolioTotals();
// Add the child panels to our JPanel
add( stockTablePanel );
add( portfolioTotalsPanel, BorderLayout.SOUTH );
// Add our class as a table model listener for the stock table
// model so that we can update the portfolio totals panel
// whenever the table changes.
stockTablePanel.stockTableModel.addTableModelListener( this );
// TableModelListener: tableChanged
public void tableChanged(TableModelEvent e)
// Make sure it is our table that changed
if( e.getSource() == stockTablePanel.stockTableModel )
// Call our method to update the portfolio totals
updatePortfolioTotals();
// public updatePortfolioTotals
// Updates the portfolio totals panel labels based off of the values
// in the stockTablePanel
public void updatePortfolioTotals()
// Get the values from the stockTablePanel and send them
// to the portfolioTotalsPanel
portfolioTotalsPanel.setDollarChange( new Float( stockTablePanel.getDollarChange() ) );
portfolioTotalsPanel.setPercentChange( new Float( stockTablePanel.getPercentChange() ) );
// Main application entry point into this class
public static void main( String[] args )
// Create a JFrame object
JFrame frame = new JFrame( "Stock Table Tab" );
// Create an StockTableTabPanel Object
StockTableTabPanel app = new StockTableTabPanel();
// Add our StockTableTabPanel Object to the JFrame
frame.getContentPane().add( app, BorderLayout.CENTER );
// Resize our JFrame
frame.setSize( 640, 440 );
// Make our JFrame visible
frame.setVisible( true );
// Create a window listener to close our application when we
// close our application
frame.addWindowListener
new WindowAdapter()
public void windowClosing( WindowEvent e )
System.exit( 0 ); -
Error when I import classes using directive JSP page
Hi all!
I have installed JDeveloper 11g (11.1.1.3.0)
My applications are located in the C:\dir (JDEV_USER_DIR = C:\dir)
I Created application "Appliation1". In it i created 2 projects (Project1, in it beans session entity and other java classes; Project2, in it JSP).
I want import classes from Project1 to Project2 using next directive:
<%@ page contentType="text/html;charset=windows-1252"
import="project1.*"%>
so in Project properties of Project2 set the way to classes in Project1.
When i run JSP an error occurred:
Error(4,9): The import project1 cannot be resolved
Maybe i'm not set correctly the way to the classes
Thanks in advance.angelr, thanks, it helped me)
In jdeveloper 10g i set address in Project Properties->Libraries and Classpath->Add JAR/Directory;
and set the way to my classes;
and it worked.
in the 11 version seems different -
Invoking a parser class from an applet resulting in exception
I wrote a xml parser to parse a string . Iam parsing the string to the constructor of the parser class . Iam instantiating the parser class from an applet in the java console of the browser the following error is thrown. But instantiating the parser class from a servlet is not possing any issues .Hope to get a reply
java.lang.VerifyError: (class: mediaspan/whiteboard/helper/SvgParser, method: <init> signature: (Ljava/lang/String;)V) Incompatible object argument for function call
at mediaspan.whiteboard.applets.KaleidaPaintFrameAppletReader.chkServer(Unknown Source)
at mediaspan.whiteboard.applets.KaleidaPaintFrameAppletReader.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)hi,
try this in Your code of SvgParser (constructor):
public SvgParser(String strfromapplet) throws SAXException{
// Create a JAXP SAXParserFactory and configure it
SAXParserFactory loSPF = SAXParserFactory.newInstance();
loSPF.setValidating(false);
XMLReader loXMLReader = null;
try{
// Create a JAXP SAXParser
SAXParser loSaxParser = loSPF.newSAXParser();
// Get the encapsulated SAX XMLReader
loXMLReader = loSaxParser.getXMLReader();
// Set the ContentHandler of the XMLReader
loXMLReader.setContentHandler(this);
// Set an ErrorHandler before parsing
loXMLReader.setErrorHandler(this);
try
// Tell the XMLReader to parse the XML document
loXMLReader.parse(strfromapplet);
catch(SAXException se)
System.err.println(se.getMessage());
System.exit(1);
catch(IOException ioe)
System.err.println(ioe);
System.exit(1);
}catch(IOException io){
io.printStackTrace(); -
New syntax to import .class Files???
Using JDK 1.2.2 i coul import my own class files by typing
import ClassName;
Using the j2sdk1.4.0 compile I get the Error Message
`.` expected
Is there a new synatx for importing .class files???Normally I don't help anyone under this username, but since the idiot Kayaman is here being his usual jerk-ness providing no meaningful help whatsoever (as usual), I'll let you in on the fact that 1.4 doesn't let you import un-packaged classes anymore. So just remove the import statement, or change your imported class into some kind of package.
-
import java.util.*;
import java.util.ArrayList,java.uitl.HashMap;
What difference it makes to the performance of a class
file when we import a specific class or an entire packageFor a great Q & A on this very question:
http://www.javaworld.com/javaworld/javaqa/2001-04/01-qa-0406-import.html?
Here is the quoted information:
"Q. Does importing an entire package cause any runtime or compile time overhead? For example, does:
import java.util.*
compared with:
import java.util.Vector
cause any added overhead?
A. In answering your questions a few definitions are helpful:
Imports of the type java.util.Vector; are referred to as single type import
Imports of the form java.util.*; are referred to as import on demand
Both import on demand and single type import are passive mechanisms. As passive mechanisms, import loads information about the package and types only when it is needed. Indeed, the compiler will load this information only when a type is actually used, not when it is simply imported. The import simply tells the compiler where to look when it actually needs a type.
So no, importing an entire package produces no more overhead than importing a specific type.
That being said, it is generally regarded as bad practice to import an entire package using import on demand. Sometimes the number of imports may be large. However, you can quickly look at the list and know what classes the importing class uses. Such a list of imports can provide important documentation to someone unfamiliar with the code. " -
Adding all dependent classes of an applet to make a jar file
Hi everyone,
I have this problem which I was not able to find a solution for, So I truly appreciate any feedback on this.
I have a project on eclipse which is basically an applet.
This applet is using some classes in some jars that I have imported as libraries for this project.
Everything works on eclipse with no problem. However I need to make a jar file of the applet and required classes to use it in an html page.
Now that's the part I have been facing difficulties, cuz I have to include all the classes that the applet is using from other jar
files. And I can not come up with a way to find out all those classes.
On the other side if I include the whole jars then my applet goes over 100 meg and would be useless.
I am going to give an example of the problem I have in hope of making it a bit clear.
I have a applet, which uses some classes from some jars. i.e., class A. but class A itself need class B and etc.
Now how can I find all these dependencies since I have to include them along the applet in the jar file I am going to make.
Once again I appreciate any feedback and sorry that is a long question.Fractalz wrote:
. . . Now that's the part I have been facing difficulties, cuz I have to include all the classes that the applet is using from other jar
files. And I can not come up with a way to find out all those classes.See the Class-Path: parameter (of a Manifest file) documentation here:
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Manifest-Overview
Maybe you are looking for
-
Error message when installing itunes on Windows XP
C:Documents and setting not vaild with Win32 applications. I do not know where to go from here.
-
"more than one application server offer ENQ service " in SICK transaction
Dear Gurus We have a problem in SICK Transaction in 4.6 b server contanining 3 instances . " more than one application server offer ENQ service" When 2 instances are stopped and run the SICK transaction for one instanse found no error but when other
-
Difference in S_ALR_87012172 & FAGLL03
Hi Gurus, We have an issue that total balance of the two reports S_ALR_87012172 & FAGLL03 are not matching. This is because of alternative recon.account maintained with respect to GL maintained in customer master. Therefore, whenever posting done f
-
Problem with printing HTML container
Hi all, I am having a problem with FlexPrintJob (or PrintJob) for the mx.controls.HTML container. On print i receive only one page (only the visible area) of my HTML container. How can i print multiple pages from mx.controls.HTML? Please Help!!!
-
Where can I find customized rfc function?
Hi. 1. I checked using wsadmin and soamanager, T-code wsadmin works forme. What I'm considering is if I connect from remote side(exp: jco) , how can I find these methods? 2. I create function via the se80, and can check in wsadmin, se 37. Is it possi