UDF error: bad class file
Hi to all!
i faced with following problem:
i'm trying to use in message mapping exported Java function and get following error:
<i>Source code has syntax error: E:/usr/sap/DXI/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb97a3fc699d611dcaf9d001b78d07a70/source/com/sap/xi/tf/_UserToRoleId_.java:3: cannot access kolpix.echo bad class file: E:\usr\sap\DXI\DVEBMGS00\j2ee\cluster\server0\.\temp\classpath_resolver\Mapb97a3fc699d611dcaf9d001b78d07a70\classpath\Echo_1(kolpix/echo.class) class file has wrong version 50.0, should be 48.0 Please remove or make sure it appears in the correct subdirectory of the classpath. import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.*;import kolpix.echo; ^ 1 error</i>
There is my Java function:
package kolpix;
public class echo {
public echo() {
public static String hello(String str) {
return "Hello "+str+"!";
in UDF into the <b>Imports</b> textField i just put <b>kolpix.echo;</b>
and in body function i just put <b>return echo.hello("World");</b>
Could any one explain what does it mean and what i must do to solve the problem?
Thx in advance.
<a href="http://j-integra.intrinsyc.com/support/kb/article.aspx?id=183240">That info explain all</a>
Similar Messages
-
BAD CLASS FILE ERROR WHEN TRYING TO CALL JAVA CLASS IN WEB-INF DIRECTORY
I AM NEW TO THIS FORUM. PLEASE HELP ME IDENTIFY/RESOLVE THIS ERROR - bad class file: /java/tomcat/webapps/ChoiceTel/WEB-INF/classes/XYZ/SMUA.class. OTHER JSP SCRIPTS THAT CALL JAVA CLASSES DO WORK WELL.
THE FUNNY THING ABOUT COMPILIING THIS JAVA CLASS WAS - I HAD TO A jar xvf OF activation.jar and mail.jar IN THE XYZ DIRECTORY BEFORE SUCCESSFULLY COMPILING SMUA.
THE CALL BEING MADE FROM THE JSP SCRIPT IS AS FOLLOWS:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<BODY>
<%@ page import="XYZ.*" %>
<%!
%>
<%
SMUA sndmail = new SMUA();
sndmail.postMail ("[email protected]","Test Subject","What Message","[email protected]");
%>
</BODY>
</HTML>Dude. Please don't shout. If your keyboard is like mine, it can produce both upper and lower case letters. Please use them appropriately.
Do you have the activation.jar/mail.jar available in the WEB-INF/lib directory for this application? -
Javac probleme: bad class file error
I'm new to java
I have two classes myPoint.jav and TestPoint.java, when I compile them, I error:
in the command line I type:
C:\otman\java>javac -g geometry\src\myPoint.java TestPoint.java
TestPoint.java:8: cannot access myPoint
bad class file: c:\otman\java\geometry\src\myPoint.class
class file contains wrong class: geometry.src.myPoint
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
myPoint p = new myPoint();
^
1 error
Can some one help me Thanks
//Here is the class c:\otman\java\TestPoint.java
import geometry.src.*;
Testing my class Point
public class TestPoint {
public static void main(String[] args) {
myPoint p = new myPoint();
System.out.println("thank you very much");
System.exit(0);
// And here is the class c:\otman\java\geometry\src\myPoint.java
package geometry.src;
class myPoint members and methods of a 3D point
public class myPoint {
private double m_x,m_y,m_z; // the coordinates
public double getx() {return m_x;}
public double gety() {return m_y;}
public double getz() {return m_z;}
public void setx(double x) {m_x=x;}
public void sety(double y) {m_y=y;}
public void setz(double z) {m_z=z;}
public void translate(double dx,double dy, double dz) {
m_x += dx;m_y += dy;m_z += dz;
// Constructor ------------------------------------------------------------
myPoint(double x,double y,double z) {
m_x=x;m_y=y;m_z=z;
myPoint() {
m_x=0;m_y=0;m_z=0;
myPoint(myPoint p) {
m_x=p.getx();m_y=p.gety();m_z=p.getz();
// ---------------------------------------------------------------------------------Thank you for the reply but still have problem.
I created a directory classes and the directories look like:
C:\otman\java\
TestPoint.java
classes\
geometry\
src\
myPoint.java
When I compile using the line command:
C:\otman\java>javac -g -d classes geometry\src\myPoint.java TestPoint.java
I get the error:
TestPoint.java:8: cannot find symbol
symbol : constructor myPoint()
location: class geometry.src.myPoint
myPoint p = new myPoint();
^
1 error
Now the directories look like:
C:\otman\java\
TestPoint.java
classes\
geometry\
src\
myPoint.class
geometry\
src\
myPoint.java
I think that myPoint was compiled without problem but TestPoint was not compiled and it gives 1 error.
Can you help me? Thanks.<!--Session data--> -
Hi
I set my java home to JDK 1.4 and execute my build.It is ok.
Then i try the same by setting JDK 1.5 as java home. build is ok.
But now i need to use only JDK 1.4.So i set my java home as jdk 1.4 and try to execute the build.xml
Now i got the error of class file has wrong version 49.0, should be 48.0
I understand that the class files(49.0) which are created by JDK 1.5 and i try to execute those by JDK 1.4.
But i donot knwo how to solve this.
Will anybody please help me to solve?
Thank youHi
I didnot compile java files with JDK 1.4 and 1.5 both.
First time i use JDk 1.4. for all java files
Second time i use JDk 1.5 for all java files.
Finally i should use JDK 1.4. So i come to jdk 1.4 and set java home jdk 1.4 and exucute my build.xml. Then i got the bad class file error.
Can u help me at this point?
Thank you -
Bad Class File error - Win2k & J2SDK1.4.0_01
Hi,
I am trying to run a 'Hello World' program which came with the FreeTTS package from links from the java.sun.com website, and am not able to compile the program. I get the error:
FreeTTSHelloWorld.java:4: cannot access file
cl.com.sun.speech.freetts.audio.Voice
bad class file: .\cl\com\sun\speech\freetts\audio\Voice.class
class file contains wrong class: com.sun.speech.freetts.Voice
Please remove or make sure it appears in the correct subdirectory of the classpath.
import cl.com.sun.speech.freetts.audio.Voice;
_______________________________________^
The FreeTTSHelloWorld.java File is printed below [its embarassingly simple..]
* Copyright 2001 Sun Microsystems, Inc.
import cl.com.sun.speech.freetts.audio.Voice;
import cl.com.sun.speech.freetts.audio.JavaClipAudioPlayer;
import cl.com.sun.speech.freetts.en.us.CMULexicon;
public class FreeTTSHelloWorld {
public static void main(String[] args) {
try {
String voiceClassName = (args.length > 0) ? args[0] :
"com.sun.speech.freetts.en.us.CMUDiphoneVoice";
Class voiceClass = Class.forName(voiceClassName);
Voice helloVoice = (Voice) voiceClass.newInstance();
helloVoice.setLexicon(new CMULexicon());
helloVoice.setAudioPlayer(new JavaClipAudioPlayer());
helloVoice.load();
helloVoice.speak
("Thank you for giving me a voice. I'm so glad to say
hello to this world.");
System.exit(0);
catch (Exception e) {
e.printStackTrace();
I've tried a billion things, including moving around the .class files [which, by the way, i extracted myself from the .jar files which came with the FreeTTS package - is that what i'm doing wrong? if so, please tell me - ] and still nothing happens - the same error results.
I've tried reading other cases similar to mine in the forums, but most of the things i read didn't apply to my (quite simple) situation, such as the 'package' line needing to be removed or anything like that..
I run Win2k and have j2sdk1.4.0_01 installed on my machine
I beg for anyone's help. Thanks in advance
-=-Miagi-=-Aha!
Extracting from the jar file might be ok, as long as the directory it's extracted into reflects the class's package name. Open the jar file using WinZip and you'll see that the files it contains are in directories that exactly mirror (including case) the package names.
The error you're getting tells you that java is looking in .\cl\com\sun\speech\freetts\audio\Voice.class (the '.\' means relative to your current working directory) and my bet would be that the file is not there!
You shouldn't need to extract these files at all, actually: Try deleting the files you extracted from the jar then try running your program again.
I hope this is helpful...
Chris. -
Cannot access Graphics - bad class file
Hey.
When I try to compile my source I get an error saying...
.\Man.java:146: cannot access Graphics
bad class file: .\Graphics.java
file does not contain class Graphics
Please remove the files or make sure it appears in the correct subdirectory.
It's on a different computer so that's not exactly it, but it's close enough. Compiler was working fine until the other day when i found out that all the source files were zipped up in src.zip, I had to extract Graphics.java so I could open it in emacs, and after I did that it started giving me that error message. There's nothhing wrong with my source, and I didn't move Graphics, it's still in the correct place exactly as it was, and i looked at it, all the right stuff is still inside. I'm quite confused.
So do I have to reinstall? That would mean a massive download on my 56k and I kinda wanna carry on with my work.You should not need to unzip src.zip to use the Graphics class or any class that comes with j2sdk. The compiled classes are in jar files that are installed in certain directories when you install the j2sdk.
You should only need to have a line "import java.awt.Graphics;" near the start of your source code.
The error most likely occurred when the compiler found a Graphics.class file but inside the file is java.awt.Graphics class, not a plain Graphics class. -
Problem in Packages while compailing the code "bad class file"
Hi,
I wrote the code for encrypt the password in .java file and i used package also
i'm importing that package and i'm compiling the .java file it throws the error like this.
regi1.java:23: cannot access EncryptPassword
bad class file: .\EncryptPassword.java
file does not contain class EncryptPassword
Please remove or make sure it appears in the correct subdirectory of the claspath
EncryptPassword enc = new EncryptPassword();
^
1 error
EncryptPassword.java
package encrypt;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import sun.misc.CharacterEncoder;
public class EncryptPassword
public EncryptPassword() { }
public EncryptPassword instance;
public String getEncrypt(String plaintext) throws Exception
MessageDigest md = null;
try
md = MessageDigest.getInstance("SHA"); //step 2
catch(NoSuchAlgorithmException e)
throw new Exception(e.getMessage());
try
md.update(plaintext.getBytes("UTF-8")); //step 3
catch(UnsupportedEncodingException e)
throw new Exception(e.getMessage());
byte raw[] = md.digest(); //step 4
String hash = (new BASE64Encoder()).encode(raw); //step 5
return hash; //step 6
public EncryptPassword getInstance() //step 1
if(instance == null)
return new EncryptPassword();
else
return instance;
}regi1.java
import encrypt.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class regi1 extends HttpServlet
public regi1(){ }
public void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
java.io.PrintWriter printwriter = httpservletresponse.getWriter();
HttpSession httpsession = httpservletrequest.getSession(true);
httpservletresponse.setContentType("text/html");
try
{ EncryptPassword enc = new EncryptPassword();
String Email = httpservletrequest.getParameter("email");
String Password = httpservletrequest.getParameter("password");
*--- some code for database connection---*
String insQry1 = "INSERT INTO register (Email, Pass);
pStmt.setString(1,Email);
pStmt.setString(2,enc.getEncrypt(Password));
catch( Exception exception)
exception.printStackTrace();
System.out.println(exception);
httpservletrequest.getRequestDispatcher("./FileSubmit.jsp").forward(httpservletrequest,httpservletresponse);
{code}Multipost: http://forum.java.sun.com/thread.jspa?threadID=5225097&tstart=0
Please continue the thread there and don't multipost!
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
(Yes I know it's on JavaRanch but I think it applies everywhere)
---------------------------------------------------------------- -
Bad class file: WSRP_v2_Registration_PortType ...
I've been trying to deploy a portlet to a 10.1.3.2 Portlet Container on OAS 10g without much luck. The portlet deploys correctly to the standalone OC4J within JDeveloper. Here is the error:
... \application-deployments\Portlet\Portlet\oasis\names\tc\wsrp\v2\bind\runtime\WSRP_v2_Registration_Binding_SOAP_Tie.java:930: cannot access oracle.portlet.wsrp.v2.soap.runtime.WSRP_v2_Registration_PortType_modifyRegistration_Fault_SOAPSerializer
bad class file: ... \application-deployments\Portlet\Portlet\oracle\portlet\wsrp\v2\soap\runtime\WSRP_v2_Registration_PortType_modifyRegistration_Fault_SOAPSerializer.java
file does not contain class oracle.portlet.wsrp.v2.soap.runtime.WSRP_v2_Registration_PortType_modifyRegistration_Fault_SOAPSerializer
Please remove or make sure it appears in the correct subdirectory of the classpath.
new oracle.portlet.wsrp.v2.soap.runtime.WSRP_v2_Registration_PortType_modifyRegistration_Fault_SOAPSerializer(ENCODE_TYPE, NOT_NULLABLE, SOAPVersion.SOAP_11), SOAPVersion.SOAP_11);
^
1 error
The class it is complaining about is in wsrp-stubs.jar. I've included the jar in my deployment from JDeveloper and placed it in OAS as a shared lib and import it into the classpath at deployment time. The sample portlets distributed with the portlet container deploy without issue. I'm out of ideas. Any thoughts you have would be appreciated. Thanks!
-JasonBoing.
-
Cannot access JScrollPane, bad class file !!!!
Hi everybody. I have got a big big problem. I can not compile my code because this message alwayes is displayed:
C:\Java\hosseindab\Dabb.java:8: cannot access JScrollPane
bad class file: .\JScrollPane.class
class file contains wrong class: javax.swing.JScrollPane
Please remove or make sure it appears in the correct subdirectory of the classpath.
private JScrollPane skrollytan;
I tried to uninstall and reinstall SDK och Textpad, but it didn't work. I even installed them on another computer, but it was the same problem. I do not know what has happened. I have tried j2SDK 1_3_1_15 and j2sdk 1_4_0_01. No use. I could compile the same files some hours ago, but now the Textpad says NO, NO, NO!!! and generates the above error. Just please help me, I don't have much time to deliver my java program.
The code is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Dabb extends JFrame implements ActionListener
private JLabel lBild1,lBild2,lBild3;
private JScrollPane skrollytan;
private JPanel panelen;
private JRadioButton knapp1, knapp2, knapp3;
private JSplitPane delning;
private ButtonGroup gruppen;
public Dabb()
lBild1 = new JLabel(new ImageIcon("Solnedg�ng.jpg"));
lBild2 = new JLabel(new ImageIcon("Vinter.jpg"));
lBild3 = new JLabel(new ImageIcon("Bl�a kullar.jpg"));
skrollytan = new JScrollPane();
panelen = new JPanel();
gruppen = new ButtonGroup();
knapp1 = new JRadioButton("Solnedg�ng",true);
knapp2 = new JRadioButton("Vinter",false);
knapp3 = new JRadioButton("Bl�a kullar",false);
delning = new JSplitPane();
delning.setLeftComponent(panelen);
delning.setRightComponent(skrollytan);
Container c = getContentPane();
c.add(delning);
delning.setMinimumSize(new Dimension(300,300));
panelen.setLayout(new BoxLayout(panelen,
BoxLayout.Y_AXIS));
gruppen.add(knapp1);
gruppen.add(knapp2);
gruppen.add(knapp3);
panelen.add(knapp1);
panelen.add(knapp2);
panelen.add(knapp3);
knapp1.addActionListener(this);
knapp2.addActionListener(this);
knapp3.addActionListener(this);
setSize(600, 400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
public void actionPerformed(ActionEvent e)
Object o = e.getSource();
if(o == knapp1)
skrollytan.setViewportView(lBild1);
else if(o == knapp2)
skrollytan.setViewportView(lBild2);
else if(o == knapp3)
skrollytan.setViewportView(lBild3);
public static void main(String [] argv)
Dabb v = new Dabb();
}Your post compiles for me, no errors.
As a guess. you have a problem classpath or mislocated or duplicate files.
This line is especially suspect: bad class file: .\JScrollPane.class
What is that leading period? Do you have a file named ScrollPane?
Something else in the computer is bad, not the program.
Try compiling from the commandline. -
This is probably a very basic issue but here it goes: I've been developing a web application in tomcat. Originally we were using the JWSDP 1.3 bundle. I decided to download tomcat 4.1.3 and tried to run the application. I keep getting "bad class errors" and something about tag pool 13 of 10. Any clue as to what is causing the problem? I think it has something to do with the classpath environment variable in windows XP, unfortunately the IT people must have changed my user rights b/c I can no longer edit/change the System variables., I've tried adding a user variable CLASSPATH with the new path to the application, but it still doesnt seem to work.
Thanks for any helpBecause this is the only post Google returns for "netbeans bad constant pool tag", I'd like to add this (even though the post is many years old):
The original post mentions Windows XP and CVS - so my recent experience may be relevant.
I moved a bunch of Netbeans projects via Windows onto a Linux server to add them to a CVS repository.
When I reentered the Projects into Netbeans all hell broke loose : for example: projects compiled clean but the IDE red-flagged them; libraries showed up on the Project Property sheets but were absent in the Libraries tab under the Project in the Projects tree. Netbeans itself appeared to be "in distress".
I had noticed that many java sources were now double-spaced (a blank line inserted after each original line). I suspected somewhere during the journey from Windows to Linux the old carriage-return + line-feed glitch had happened. But, hey-ho, this doesn't effect the java and could be filtered out later.
Then the moment of revelation: most of the XML and .properties files had also been double-spaced.
So code that originally read (for example):
javac.classpath=\
foo:\
bar
now read:
javac.classpath=\
foo:\
bar
This (subtle) introduction of the extra lines ruins everything ... but once you realise what's happened, it is easily fixed ! -
In PI 7.1 - Java UDF's Compiled Class files - Jar File location
Hi All,
In PI 7.1 Does anybody know where the compiled Java UDF's (which are used in Graphical mapping) class files stored in jar are located in integration server? I want to use this jar file in my XSLT mapping.Hi,
I guess it would be under
\usr\sap\<SID>\DVEBMGS00\j2ee\cluster\server0\temp\classpath_resolver
or
\usr\sap\<SID>\DVEBMGS00\j2ee\cluster\server0\.\temp\classpath_resolver
Where SID is your XI instance name.
Thanks,
Gujjeti
Edited by: Praveen Gujjeti on Jun 23, 2008 5:12 PM -
Do java programms after giving compilation error generates .class file?
Do java programms after giving compilation error generates the .class file?
Do any outer class may have the private as access modifier?
If someone asks you that -do any program in java after giving a compilation error gives the .class file -do any class except(inner class)
be defined as private or static or protected or abc or xxx Now type the
following program
private class test
public static void main(String s[])
System.out.println("Hello!How are You!!");
-Compile it.... You must have
received this error test.java:1:The type type can't be private. Package members are always accessible within the current package. private class
test ^ 1 error
Here please notify that compiler has given the
error not the warning therfore .class file should not be created but now type
>dir *.class
___________ and you will see that the
test.class file existing in the directory nevertheless this .class file
is executable. if you will type __________________ >java test
it will
wish you Hello! and suerly asks you that How are You!! ________________!
You can test it with the following as acces modifiers and the progrm will run Ofcourse it will give you compilation error.
protected
xxx
abc
xyz
private
Do you have any justification?Hmm,
I've been working with different versions of jdk since, if I'm not mistaken, jdk1.0.6 and never was able to get *.class with compilation errors. It was true for Windows*, Linux, and Solaris*.
About the 'private'/'protected' modifier for the type (class) - it makes perfect sence not to allow it there: why would anyone want to create a type if no one can access it? There should be a reason for restricting your types - let's say, any inner class can be private/protected.
For ex., you shouldn't have compile problems with this:
class Test
public static void main(String s[])
System.out.println("Hello!How are You!!");
private class ToTest{}
Sorry, but I don't really know where you can read up on that. -
Cannot acces (a class), bad class file, class file contains wrong class
Hi,
I am trying to implement a Java package and I've never done this before. The package is called 'randomX' and I downloaded it from here: http://www.fourmilab.ch/hotbits/source/randomX/randomX.html
I downloaded the .tar file on my Windows Vista system, unzipped it, and dragged and dropped into(in my case): C:\Program Files\Java\jdk1.6.0_05\src\java\util
This is also the directory where Random.java is, so I figured it went there, plus the Java Documentation says that, I think.
The Java Docs are here: http://www.fourmilab.ch/hotbits/source/randomX/doc/
Thanks in advance,
Rommel.dcminter wrote:
No. That's not right - you need to put the JAR file into your classpath.
[http://en.wikipedia.org/wiki/Classpath_(Java)|http://en.wikipedia.org/wiki/Classpath_(Java)]
If it doesn't come with a JAR file then you'll need to build it first. Sounds like that might be outside your comfort zone.Thanks for the link and the tip. I have no idea what a JAR file is, much less how to build one.
However, the thing has a "Makefile" file. Can I build the JAR from this?
# Makefile for randomX package
JAVA = /usr/java/jdk1.5.0_06
CLASSPATH = $(JAVA)/classes:..:.
SRC = randomX.java randomJava.java randomHotBits.java randomLCG.java \
randomMCG.java randomLEcuyer.java randomXdemo.java
CLASS = $(SRC:.java=.class)
all:
javac -classpath .. *java ; cp -p *class randomX
test:
java randomXdemo
clean:
rm -f *.bak *.class
rm -rf doc
mkdir doc
rm -rf randomX
mkdir randomX
RELEASE = $(SRC) Makefile
release:
tar cfvz randomX.tar.gz $(RELEASE)
html:
javadoc -classpath $(CLASSPATH) -d doc *.java
images:
( cd $(JAVA)/images ; tar cfv /tmp/ZZimages.tar . )
rm -rf doc
mkdir doc
mkdir doc/images
(cd doc/images ; tar xfv /tmp/ZZimages.tar )
rm -f /tmp/ZZimages.tar
touch randomX.java
.SUFFIXES: .java .class -
http://forum.java.sun.com/thread.jsp?forum=54&thread=349902&tstart=0&trange=15
(a) I don't see any dukes, and (b) the link doesn't work. :)
-
Trying to move inner class to a class file
Hi folks,
I keep getting an error which puzzles me. I cut the following class (MyDocumentListener) out of an outer class (CenterPanel).
MyDocumentListener compiles OK but...
Now when I compile the outerclass I get the folowing error:
C:\divelog> javac -classpath C:\ CenterPanel.java
CenterPanel.java:54: cannot access divelog.MyDocumentListener
bad class file: C:\divelog\MyDocumentListener.class
class file contains wrong class: MyDocumentListener
Please remove or make sure it appears in the correct subdirectory of the classpath.
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define
the listener class
^
1 error
... yes I checked, it is there..
C:\divelog>dir m*.j*
Directory of C:\divelog
MYDOCU~1 JAV 936 03-04-03 11:16p MyDocumentListener.java
====================================================================
MyDocumentListener tests to see if the current document has changed.
Required fields: boolean documentWasChanged;
import javax.swing.event.*;
// ------ Document listener class -----------
public class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
wasChanged(e);
public void removeUpdate(DocumentEvent e) {
wasChanged(e);
public void changedUpdate(DocumentEvent e) {
public boolean wasChanged(DocumentEvent e) {
// indicate that the document was changed
//and test before opening another file or closing the application.
boolean documentWasChanged = true;
return documentWasChanged;
} // close class MyDocumentListener
====================================================================
package divelog;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
// import javax.swing.text.JTextComponent.*;
import javax.swing.text.*;
public class CenterPanel extends JPanel implements ActionListener
{ // Opens class
static private final String newline = "\n";
private JTextArea comments;
private JScrollPane scrollpane;
private JButton saveButton, openButton;
private JLabel whiteshark;
private Box box;
private BufferedReader br ;
private String str;
private JTextArea instruct;
private File defaultDirectory = new File("C://divelog");
private File fileDirectory = null;
private File currentFile= null;
// public boolean changed;
public boolean documentWasChanged;
public CenterPanel()
{ // open constructor CenterPanel
setBackground(Color.white);
comments = new JTextArea("Enter comments, such as " +
"location, water conditions, sea life you observed," +
" and problems you may have encountered.", 15, 10);
comments.setLineWrap(true);
comments.setWrapStyleWord(true);
comments.setEditable(true);
comments.setFont(new Font("Times-Roman", Font.PLAIN, 14));
// add a document listener for changes to the text,
// query before opening a new file to decide if we need to save changes.
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
comments.getDocument().addDocumentListener(myDocumentListener); // create the reference for the class
scrollpane = new JScrollPane(comments);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
saveButton = new JButton("Save Comments", new ImageIcon("images/Save16.gif"));
saveButton.addActionListener( this );
saveButton.setToolTipText("Click this button to save the current file.");
openButton = new JButton("Open File...", new ImageIcon("images/Open16.gif"));
openButton.addActionListener( this );
openButton.setToolTipText("Click this button to open a file.");
whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER);
Box boxH;
boxH = Box.createHorizontalBox();
boxH.add(openButton);
boxH.add(Box.createHorizontalStrut(15));
boxH.add(saveButton);
box = Box.createVerticalBox();
box.add(scrollpane);
box.add(Box.createVerticalStrut(10));
box.add(boxH);
box.add(Box.createVerticalStrut(15));
box.add(whiteshark);
add(box);
} // closes constructor CenterPanel
public void actionPerformed( ActionEvent evt )
{ // open method actionPerformed
// --------- test to see if the current file was modified and give an option to save first.
if (documentWasChanged) // add and IF filename not null
// ----- display pop-up alert --------------------------------------------------------------
int confirm = JOptionPane.showConfirmDialog(null,
"Click OK to discard current changes, \n or Cancel to save before proceeding.", // msg
"Unsaved Modifications!", // title
JOptionPane.OK_CANCEL_OPTION, // buttons displayed
// JOptionPane.ERROR_MESSAGE
// JOptionPane.INFORMATION_MESSAGE
// JOptionPane.PLAIN_MESSAGE
// JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE,
null);
if (confirm != JOptionPane.YES_OPTION) //user wants to save changes
try {
// let user save the file
catch(Exception e) {}
else // let user open a new file
} // close "if (documentWasChanged)" - display pop-up alert ----------
JFileChooser jfc = new JFileChooser();
//Add a custom file filter and disable the default "Accept All" file filter.
jfc.addChoosableFileFilter(new JTFilter()); // /** found in Utils.java /*
jfc.setAcceptAllFileFilterUsed(false);
// -- open the default directory --
// public void setCurrentDirectory(File dir)
// jfc.setCurrentDirectory(new File("C://divelog"));
jfc.setCurrentDirectory(defaultDirectory);
jfc.setSize(400, 300);
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
Container parent = saveButton.getParent();
//========================= Test Button Actions ================================
//========================= Open Button ================================
if (evt.getSource() == openButton)
int choice = jfc.showOpenDialog(CenterPanel.this);
File file = jfc.getSelectedFile();
// --------- change test was here -----------
/* a: */
if (file != null && choice == JFileChooser.APPROVE_OPTION)
String filename = jfc.getSelectedFile().getAbsolutePath();
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
try
{ //opens try
comments.getLineCount( );
// -- clear the old data before importing the new file --
comments.selectAll();
comments.replaceSelection("");
// -- get the new data ---
br = new BufferedReader (new FileReader(file));
while ((str = br.readLine()) != null)
{//opens while
comments.append(str);
} //closes while
} // close try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Open command not successful:" + ioe + newline);
} // close catch
// ---- display the values of the directory variables -----------------------
comments.append(
newline + "The f directory variable contains: " + f +
newline + "The fileDirectory variable contains: " + fileDirectory +
newline + "The defaultDirectory variable contains: " + defaultDirectory );
else
comments.append("Open command cancelled by user." + newline);
} //close if statement /* a: */
//========================= Save Button ================================
} else if (evt.getSource() == saveButton)
int choice = jfc.showSaveDialog(CenterPanel.this);
if (choice == JFileChooser.APPROVE_OPTION)
File fileName = jfc.getSelectedFile();
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
//check for existing files. Warn users & ask if they want to overwrite
for(int i = 0; i < fileName.length(); i ++) {
File tmp = null;
tmp = (fileName);
if (tmp.exists()) // display pop-up alert
//public static int showConfirmDialog( Component parentComponent,
// Object message,
// String title,
// int optionType,
// int messageType,
// Icon icon);
int confirm = JOptionPane.showConfirmDialog(null,
fileName + " already exists on " + fileDirectory
+ "\n \nContinue?", // msg
"Warning! Overwrite File!", // title
JOptionPane.OK_CANCEL_OPTION, // buttons displayed
// JOptionPane.ERROR_MESSAGE
// JOptionPane.INFORMATION_MESSAGE
// JOptionPane.PLAIN_MESSAGE
// JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE,
null);
if (confirm != JOptionPane.YES_OPTION)
{ //user cancels the file overwrite.
try {
jfc.cancelSelection();
break;
catch(Exception e) {}
// ----- Save the file if everything is OK ----------------------------
try
{ // opens try
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
bw.write(comments.getText());
bw.flush();
bw.close();
comments.append( newline + newline + "Saving: " + fileName.getName() + "." + newline);
break;
} // closes try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Save command unsuccessful:" + ioe + newline);
} // close catch
} // if exists
} //close for loop
else
comments.append(newline + "Save command cancelled by user." + newline);
// ========= }
} // end-if save button
} // close method actionPerformed
} //close constructor CenterPanel
// <<<<<<<<<<<<<<<<<
// <<<<<<<<<<<<<<<<< MyDocumentListener class was here <<<<<<<<<<<<<<<<<
// <<<<<<<<<<<<<<<<<
} // Closes class CenterPanelYou didn't put your MyDocumentListener class in the package divelog.
Add
package divelog;to the top of MyDocumentListener.java and recompile.
Maybe you are looking for
-
How do I disable my old apple ID where I have 1) forgotten the password, 2) the email is no longer valid (so they can't send me my password) and 3) it has my incorrect birthday (so I can't answer the security question to have them send me a new passw
-
How to populate select boxes in custom work flows?
We are trying to create a workflow that allows users to select a few item details from a select box inside the form. I created the select box but I can't figure out how to populate it with elements. I've been reluctant to post here because this quest
-
I have Itunes Music and Itunes Media folders that have almost the same gigs in them, the media is larger. Do I need both of these? I am left with 12 gigs of 500 gig hard drive and it is because of all the music I have. Can I get rid of one of these
-
What's your game plan for tomorrow?
How are you going about getting the iPad 2 tomorrow or are you waiting a few days after the rush dies down? I want to get mine from Sams and im not sure yet if my location will have it tomorrow so I'll have to wait and see but hubby will be picking m
-
I am trying to add a full screen mode button for non scalable pubished video in captivate 7
I am trying to add a full screen mode button for non scalable pubished video in captivate 7. For captivate 6 I used a widget from CPguru but that is not compatible with captivate 7.