Simple Java help
OK, I'm new to Java programming and have a project due in class next week. I'm writing a simple gradebook program that takes a grade for a term paper and a pass/fail for two essays and computes the result. I know that the visual portion of this works so I won't bore you all with that. I think the problem is somewhere in the syntax of my actionPerformed function. Here it is
String essayResult1 = essayBox1.getSelectedItem();
String essayResult2 = essayBox2.getSelectedItem();
int essayPoints1, essayPoints2, termPoints;
if(essayResult1.equals("Pass")) essayPoints1=15;
if(essayResult2.equals("Pass")) essayPoints2=15;
Character letterGrade = termField.getText();
if(letterGrade.equals("A")) termPoints=70;
else if(letterGrade.equals("B")) termPoints=60;
else if(letterGrade.equals("C")) termPoints=50;
else if(letterGrade.equals("D")) termPoints=40;
else if(letterGrade.equals("F")) termPoints=0;
else {
outputField.setText("Error");
return;}
String finalScore=new String("" + (essayPoints1+essayPoints2+termPoints));
outputField.setText("Done");
I would appreciate any help you experienced programers have. Even a hint as to which lines I'm mangling would be of great help.
If you could put [code] and [/code] tags around your code it would be much more readable.
So what is wrong? Do you get a compiler error? Does it give you incorrect results? Do you receive a run-time error?
Similar Messages
-
I am in the process of doing a Proof Of Concept / Evaluating products that can help us build a Java Application to Convert a PDF document to a Searchable PDF.
I wanted to check is there any simple JAVA API from Adobe to achive this ? Any direction in this regard is greatly appreciated.@You can achieve this using LiveCycle PDF Generator JAVA API. You can find required code here:
Adobe LiveCycle * Quick Start (SOAP mode): Converting a Microsoft Word document to a PDF document using the Java API
In parameters:
//Set createPDF2 parameter values
String adobePDFSettings = "Standard";
String securitySettings = "No Security";
String fileTypeSettings = "Standard OCR";
"Standard OCR" file type setting will run OCR on input pdf. In the code, instead of doc file provide a pdf file. Resultant pdf will be searchable PDF i.e OCRed PDF.
Feel feel to ask any further questions. -
How to bundle java help class into jar file ?
Hi, all,
I have some package in my project, with which I have a java help jar file as classpath, when I run my project, I need the jh.jar file in directory /jar/jh.jar.
Now, I bundled all my class packages into a jar file, my.jar, together with the /jar directory. When i run my jar file with command:
java -jar my.jar
It tells me couldn't find javahelp class.
What shall I do? How can I create my jar file with the jh.jar?
Thanks in advance.I think you'd be better off just adding the jh.jar as
a classpath argument and running it like that:
java -classpath /myjavalibdir/jh.jar -jar myjar.jar
...otherwise you're stepping into redistribution of
binary issues licensing-wise. That won't work either; when you run java with the -jar option, it ignores both the -classpath option and the CLASSPATH environment variable. However, it will see jh.jar automatically if you put it in the <path-to-java>/jre/lib/ext directory. But for distribution purposes, it might be simpler just to combime the contents of jh.jar into myjar.jar (if you use Ant, its <jar> task makes that very easy). Or, you can just run it this way:java -classpath myjar.jar;jar/jh.jar MyMainClassBTW, I don't think redistribution is a problem; otherwise how anyone even use JavaHelp? -
Problem while executing simple java program
Hi
while trying to execute a simple java program,i am getting the following exception...
please help me in this
java program :import java.util.*;
import java.util.logging.*;
public class Jump implements Runnable{
Hashtable activeQueues = new Hashtable();
String dbURL, dbuser, dbpasswd, loggerDir;
int idleSleep;
static Logger logger = Logger.getAnonymousLogger();
Thread myThread = null;
JumpQueueManager manager = null;
private final static String VERSION = "2.92";
public Jump(String jdbcURL, String user, String pwd, int idleSleep, String logDir) {
dbURL = jdbcURL;
dbuser = user;
dbpasswd = pwd;
this.idleSleep = idleSleep;
manager = new JumpQueueManager(dbURL, dbuser, dbpasswd);
loggerDir = logDir;
//preparing logger
prepareLogger();
private void prepareLogger(){
Handler hndl = new pl.com.sony.utils.SimpleLoggerHandler();
try{
String logFilePattern = loggerDir + java.io.File.separator + "jumplog%g.log";
Handler filehndl = new java.util.logging.FileHandler(logFilePattern, JumpConstants.MAX_LOG_SIZE, JumpConstants.MAX_LOG_FILE_NUM);
filehndl.setEncoding("UTF-8");
filehndl.setLevel(Level.INFO);
logger.addHandler(filehndl);
catch(Exception e){
logger.setLevel(Level.ALL);
logger.setUseParentHandlers(false);
logger.addHandler(hndl);
logger.setLevel(Level.FINE);
logger.info("LOGGING FACILITY IS READY !");
private void processTask(QueueTask task){
JumpProcessor proc = JumpProcessorGenerator.getProcessor(task);
if(proc==null){
logger.severe("Unknown task type: " + task.getType());
return;
proc.setJumpThread(myThread);
proc.setLogger(logger);
proc.setJumpRef(this);
task.setProcStart(new java.util.Date());
setExecution(task, true);
new Thread(proc).start();
private void processQueue(){
//Endles loop for processing tasks from queue
QueueTask task = null;
while(true){
try{
//null argument means: take first free, no matters which queue
do{
task = manager.getTask(activeQueues);
if(task!=null)
processTask(task);
while(task!=null);
catch(Exception e){
logger.severe(e.getMessage());
logger.fine("-------->Sleeping for " + idleSleep + " minutes...hzzzzzz (Active queues:"+ activeQueues.size()+")");
try{
if(!myThread.interrupted())
myThread.sleep(60*1000*idleSleep);
catch(InterruptedException e){
logger.fine("-------->Wakeing up !!!");
}//while
public void setMyThread(Thread t){
myThread = t;
/** This method is only used to start Jump as a separate thread this is
*usefull to allow jump to access its own thread to sleep wait and synchronize
*If you just start ProcessQueue from main method it is not possible to
*use methods like Thread.sleep becouse object is not owner of current thread.
public void run() {
processQueue();
/** This is just another facade to hide database access from another classes*/
public void updateOraTaskStatus(QueueTask task, boolean success){
try{
manager.updateOraTaskStatus(task, success);
catch(Exception e){
logger.severe("Cannot update status of task table for task:" + task.getID() + "\nReason: " + e.getMessage());
/** This is facade to JumpQueueManager method with same name to hide
*existance of database and SQLExceptions from processor classes
*Processor class calls this method to execute stored proc and it doesn't
*take care about any SQL related issues including exceptions
public void executeStoredProc(String proc) throws Exception{
try{
manager.executeStoredProc(proc);
catch(Exception e){
//logger.severe("Cannot execute stored procedure:"+ proc + "\nReason: " + e.getMessage());
throw e;
*This method is only to hide QueueManager object from access from JumpProcessors
*It handles exceptions and datbase connecting/disconnecting and is called from
*JumpProceesor thread.
public void updateTaskStatus(int taskID, int status){
try{
manager.updateTaskStatus(taskID, status);
catch(Exception e){
logger.severe("Cannot update status of task: " + taskID + " to " + status + "\nReason: " + e.getMessage());
public java.sql.Connection getDBConnection(){
try{
return manager.getNewConnection();
catch(Exception e){
logger.severe("Cannot acquire new database connection: " + e.getMessage());
return null;
protected synchronized void setExecution(QueueTask task, boolean active){
if(active){
activeQueues.put(new Integer(task.getQueueNum()), JumpConstants.TH_STAT_BUSY);
else{
activeQueues.remove(new Integer(task.getQueueNum()));
public static void main(String[] args){
try{
System.out.println("The length-->"+args.length);
System.out.println("It's " + new java.util.Date() + " now, have a good time.");
if(args.length<5){
System.out.println("More parameters needed:");
System.out.println("1 - JDBC strign, 2 - DB User, 3 - DB Password, 4 - sleeping time (minutes), 5 - log file dir");
return;
Jump jump = new Jump(args[0], args[1], args[2], Integer.parseInt(args[3]), args[4]);
Thread t1= new Thread(jump);
jump.setMyThread(t1);
t1.start();}
catch(Exception e){
e.printStackTrace();
} The exception i am getting is
java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe
Exception in thread "main" ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820] Please help me.....
Thanks in advance.....sathyaI am not willing to wade through the code, but this portion makes me conjecture your using an Oracle connect string instead of a class name.
java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe -
How to Deploy a Simple Java Web service in Oracle E Business Suite Server
Hi,
I have created a simple Java webservice using Jdev11g.
I am able to Test the Webservice using Jdev11g itself.
How Can i migrate the same to Oracle E Busienss Suite( - 9iAS ) so that webservice clients connect to 9iAS instead of my local machine
Thanks,
Gowtam.Hi Sudhakar,
If you are used to working with ant then you can very well use eclipse to deploy your web service.
You would usually have the ant script in the source root working directory. From eclipse if you select the build file from the navigator view and right click you will see a run ant option in the pop up menu.
Select that option and you would be able to see each targets with a checkbox select option. So define each target maybe one for wsdl2java conversion, one for compilation and one for deploying your web services. You can either make all of them run by having depends option on or you can run them individually as it takes your fancy.
I am not sure about debugging a web service yet.
Hope this helps
Aviroop
The truth is out there? Does anyone know the URL? -
Calling simple Java Code from 11g BPM
Hi,
I know this has been round the houses but I cant find a satisfactory solution for my scenario. I would like to call some simple java code from BPM (11.1.1.6). I guess I need to expose it as a service but it seems overkill to be via soap so any advice you can give would be much appreciated. Creating a jar that I can call somehow would be perfect.
This is my scenario:
- I am creating a Security POC for BPM
- The BPM Process is exposed as a web service and authenticated using SAML
- I am testing by calling the WS from OSB
- I want to be able to get the WLS Principal and display the username and the roles for the launching user, from within the BPM process
- This is possible using some simple weblogic client api code shown below
- So all I want to do is call this code from BPM somehow
- Anyone point me in the right direction ?
cheers
Tony
subject = Security.getCurrentSubject();
for(Principal p: subject.getPrincipals()) {
if(p instanceof WLSGroupImpl) {
groupList.add(p.getName());
} else if (p instanceof WLSUser) {
principal = p.getName();
}The problem to communiate java classes and forms solved !
i have add my .jar file to $OA_JAVA/oracle/apps/fnd/jar and now i can communicate between forms and java.
I can create an object, i can get simple message from class, but when i try to create
ServiceFactory factory = ServiceFactory.newInstance();
ive got ORA-105100...
can anybody help ? -
How to Run a .sql file from simple java class
How to execute a .sql file consisting of Complex Queries,procedures through simple java class.
The queries may have different delimiters,queries independant of each other.
I am able to do with Specific De-limiter.But I need in such a way that there should not be any
Constraints. Since My .sql may Contain different De-limiters.
If any one can Suggest Some Solution.
It will be Great Help.
regards
AnilCheck out ibatis script runner, it' a third party library but quite handy for running sql files...
m -
How to update the file in simple java archive file on Netweaver2004s
We have a J2EE application containing few properties file packed inside a java archive. These properties are Configuration properties which we are required to change few times after deployment.We are using SAP Visual Administrator to deploy\undeploy our application.We found out that Visual Administrator dose not support update of files packed in a simple Java Archive in Single File Update Option. It only allows updates of EJB Modules archive.
Please let us know if there is any other way we can update a file inside a simple java archive.Well, Thanks for the help but,. i didn't understand
try not opening the file every time. As I only know that I need to open a file if i would like to update the records..
The update is not happening :
Firstly it shows like this (new.txt):
STOPSecondly it must show like this (new.txt) BUT NOT HAPPENING AS I EXPECTED:
STOPSTOPBut it's not hapenning -
Can we call a simple java application from ESB
Please let me know how this can be done by using a ESB. The application jar exists on the host server. How we can pass parameters etc and receive results from this application.
Any help will be greatly appreciated.
PrakashNot sure if I completely understand your question, but you can certainly try following ways:
- call your java application via WSIF. ESB with JAVA wsif is available in 10.1.3.3.1 only (it is not supported in 10.1.3.3 very well).
- you will have to include this jar file in server.xml or bpel/system/classes so that it is available to the SOA jvm.
- You mentioned it is simple java application, but if your java API has complex (object) input and output, you will need some work
HTH,
Chintan -
Securing Web Services based on simple Java Classes
Hi @all!
We`ve got the following problem.
There`s a .NET client calling our Web services deployed on Bea Weblogic 8.1 (without
SP).
The Web Services are generated by the ANT task servicegen. They are based on simple
Java classes containing the service methods as public members.
Is there a possibility to secure these methods without using the console menu
item "Define Security Policy" ?
We can`t use this menu because it has got a javascript bug with methods returning
an array.
Thanks in advance for help.
MichaelHi Michael,
Could you use transport level security, SSL [1]?
I'm not sure what limitation you are experiencing with the console? Is
there a traceback? Have you contacted customer support on this issue?
Thanks,
Bruce
[1]
http://edocs.bea.com/wls/docs81/webserv/security.html#1053203
Michael Albrecht wrote:
>
Hi @all!
We`ve got the following problem.
There`s a .NET client calling our Web services deployed on Bea Weblogic 8.1 (without
SP).
The Web Services are generated by the ANT task servicegen. They are based on simple
Java classes containing the service methods as public members.
Is there a possibility to secure these methods without using the console menu
item "Define Security Policy" ?
We can`t use this menu because it has got a javascript bug with methods returning
an array.
Thanks in advance for help.
Michael -
Simple Java Example for DI API
Hello,
I have a Java Application and would like to connect to a SAP BO Database using JCO and DI API.
I want a simple java example that just connects to the BO Database and returns an item name or value or a recordset from the database.
Since i dont have the names of what kind of fields, items , tables exist in the SAP BO Demo database i need a basic example to make sure that i can connect to the database and retrieve data from the DB.
Any help in this regard would be appreciated...
AmitDear Amit Hingher,
The B1 JCO is a java wrapper for DI API so basically you could refer to DI help for all objects, methods and properties.
Here the jave sample for connection function:
package test;
import com.sap.smb.sbo.api.*;
public class ConnectSAP {
// company interface
public ICompany company;
private SBOErrorMessage errMsg = null;
public static void main(String[] args) {
ConnectSAP company = new ConnectSAP();
company.conn();
//method make connection andinitialize company instance
public int conn() {
int rc = 0;
try {
company = SBOCOMUtil.newCompany();
company.setServer("(local)");
company.setCompanyDB("test");
company.setUserName("manager");
company.setPassword("manager");
company.setDbServerType(...);
company.setUseTrusted(new Boolean(false));
company.setLanguage(SBOCOMConstants.BoSuppLangs_ln_English);
company.setDbUserName("Sa");
company.setDbPassword("123");
company.setAddonIdentifier("...");
company.setLicenseServer("...");
rc = company.connect();
if (rc == 0) {
System.out.println("Connected!");
} else {
errMsg = company.getLastError();
System.out.println(
"I cannot connect to database server: "
+ errMsg.getErrorMessage()
+ " "
+ errMsg.getErrorCode());
} catch (Exception e) {
e.printStackTrace();
return -1;
return rc;
public void freeConnection(){
company.disconnect();
Best Regards
Jane Jing
SAP Business One Forums team -
can i have a file2file scenario which uses simple java-mapping. As i m new to Java, jus wanna learn how it happens.
I wanna know how to code the Java mapping .....and how to utilize it in the Interface Mapping.....
I know a bit of DOM parsing..Hi,
see the below links
http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm
DOM parser API
http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html
Check this blog on Mapping:
/people/ravikumar.allampallam/blog/2005/02/10/different-types-of-mapping-in-xi
Also, check this thread for more info,
Different types of Mapping in XI
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2flibrary%2fxi%2fxi-design_configuration%2ffileValidationsinSAPXI-ACaseStudy.pdf
http://www.cafeconleche.org/books/xmljava/chapters/ch09.html
http://www.cafeconleche.org/books/xmljava/chapters/ch06.html
Check these blogs for reference..
/people/udo.martens/blog/2006/08/23/comparing-performance-of-mapping-programs
/people/ravikumar.allampallam/blog/2005/06/24/convert-any-flat-file-to-any-idoc-java-mapping
java mapping /people/amol.joshi2/blog/2006/03/10/think-objects-when-creating-java-mappings
Regards
Chilla -
Can anyone tell me the class diagrams of a simple java notepad
hi,
Can anyone tell me the class diagrams of a simple java notepad.
i'm a very beginner in UML.
thanks in advance.
MoazzamDon't worry too much about that. Figure out what it needs to do. Then grab JUnit and start writing tests & code.
On xprogramming.com there is a series of articles developing a notepad type app in C#. That might be of some help.
Dave -
Please point me to some resource (like opensource projct) for the following requirement:
I want to setup a simple Java Server which accepts XML formatted files from clients via TCP sockets. I know Enhydra project, but I am looking for something much simpler and smaller to manage.
Thanks for any helpYou can use SOAP.
Soap server accept xml messages on a variety of protocols like http, tcp etc.
Check out the open source Java implementation of soap at http://xml.apache.org/soap.
hope this helps.
regards,
Abhishek. -
Simple Java Bean Generator use
Hello everybody,
I'd like to know if someone managed to use the Simple Java Bean Generator, useful tool for web dynpro application in order to import complete database model.
I read the doc, and I think it's usable for SQLServer database. My command is as follows :
java -D com.sap.test.DBTest com.microsoft.jdbc.sqlserver.SQLServerDriver sa 123erty TSP c:\GenerateDB CONFIG
where CONFIG is my database name, sa/123erty the couple login/pwd, and TSP the pattern (what does it mean pattern in this case ?).
When executing this command, the response is : datasouce not found and driver not specified...
I don't understand, can someone help me please ??
Thanx.
Message was edited by: Sistiaga MarcThanks about your answer.
Without code modifying I wan't to use it with a Maxdb database.
Which driver is ucurrently used ? com.sap.dbtech.jdbc.DriverSapDB ?
Where do i have to launch this script knowing that my J2EE engine is installed in a linux platform ?
My command become :
java -D com.sap.test.DBTest com.sap.dbtech.jdbc.DriverSapDB SAPNW1DB SAPNW1DB CC_ c:\GenerateDB CONFIG_DB
and i always get the response : datasource not found,n driver not specified...
Am I wrong to try this generator in a windows platform where j2ee engine is in a linux platform ??
Thanx a lot in advance !
Maybe you are looking for
-
i need to update my ipod but it wont let me. keeps throwing out error code -1.
-
Help me to view my mistakes in mouseMoved
Hallo ! I've been around here looking for an article or discussion about mouseMoved..but none has answered my problem. Hmm..how do I describe my problem...ok, sorry for the long ass post here, but I am not a good expainer. The Case: I want to make a
-
Hey there. Is there a way to set up the magnetic lasso tool so that if you happen to click in the same spot twice it wont close your selection? Thanks!
-
[SOLVED]How to use pulseaudio with in 32 bit chroot on ARch64
I am trying to running some 32bit software from chroot environment on Arch64. I set up pulseaudio on Arch64 property. However, within 32 bit chroot, I cannot use pulseaudio. For an example, arch32 chroot /home/xxxx/Audio > paplay Front_Center.wav Con
-
Using national characters in Reports Parameter Form
Hi, I have Reports Server 11gR1. When I specify paramform=yes when running report, I get Parameters Form. If I specifiy any national character in parameter form field, it is not send to Reports Server. Instead of my character, question mark (?) is se