New to java (using std I/O)
Dear group,
I am going to use java for practice problem solving in
http://acm.uva.es/p
They have give some restrictions of using java I/O which they
have specified in the following link:
http://online-judge.uva.es/board/viewtopic.php?t=7429
I could not able to understand the explanation and the sample
code too because I have been doing toy programs in C/C++. My problems
is with simple stdin, similarly like C' scanf().
After going through the above links can any one give any url or tut.
Thanks for any help.
> Dear group,
I am going to use java for practice problem
solving in
http://acm.uva.es/p
y have give some restrictions of using java I/O which
they
have specified in the following link:
http://online-judge.uva.es/board/viewtopic.php?t=7429
I could not able to understand the explanation and
the sample
code too because I have been doing toy programs in
C/C++. My problems
is with simple stdin, similarly like C' scanf().
After going through the above links can any one
give any url or tut.
hanks for any help.
Instead of C's scanf() method, you use Main.ReadLn(int) to get a String from the console. It isn't even necessary to understand that method in order to submit your code.
The example they posted (http://acm.uva.es/p/data/p100.java.html) can be copied and pasted. You can even submit that example, and it will be accepted.
If you still have problems with it, why not use C or C++ instead?
Similar Messages
-
New to Java, using Vista, can't find javaws?
i'm used to running java on windows 2000, and now i am using windows vista. i used to be able to type javaws in the run program and get java to pop up, but with the new os it tells pops up a info sheet? has anyone seen this? i downloaded the latest java and also the previous version i had running on my old computer with windows 2000, both had the same result
please helpRun away from vista~
-
Very New To Java, Using Sun One Studio
I am doing a small work project for a company and they would like me to do a small project using the JavaMail API and the Java One Studio.
Now I have some experience with Java, It is installing the JavaBeansTM Activation Framework and the JavaMail API to my Classpath.
How do I figure out what my class path is?
Thanks MikeIf on windows or unix, in a shell, type set.
If on mac OS, then I don't know. Sorry. -
How do I get rid of the alert "(Java Scriprt Application)Type error: Text is undefined> I get it when I get a new Internet page using Firefow
I do not want to half to install things into my PC that i do not trust! I just want this gone and like i said Firefox should of given us the choice to add this and not forced us, because if there is no actual way to remove it then il be forced to remove Firefox till they either remove it or allow us to remove it!
-
New virtual Directory using JAVA
Hello Friends;
I want to create a folder under SAP j2ee engine and i want to upload my files under new folder and use it like
http://portal:port/Newfolder/mynew_photo.jpg
It is possible in iis. For ex. i can create a folder manuel under
c:\inetpub\wwwroot\new_folder
and after i put my files i can use it
http://iisserver:port/new_folder/new_photo.jpg
I have tried this directories
D:\usr\sap\p50\JC01\j2ee\cluster\server0\apps\sap.com
D:\usr\sap\p50\JC01\j2ee\cluster\server0\apps\
D:\usr\sap\p50\JC01\j2ee\cluster\server0\
and i have create new folder but i couldnt use it.
I hope that i have explained my question.
Thanks in Advance
Best RegardsDear Eray,
You can use the following Java code to create the Folder (Directory) in the SAP J2EE Engine and add the contents in the Directory
import java.io.*;
class CreateDirectory
public static void main(String args[])
try{
String strDirectoy ="test";
String strManyDirectories="dir1/dir2/dir3";
// Create one directory
boolean success = (new File(strDirectoy)).mkdir();
if (success) {
System.out.println("Directory: " + strDirectoy + " created");
// Create multiple directories
success = (new File(strManyDirectories)).mkdirs();
if (success) {
System.out.println("Directories: " + strManyDirectories + " created");
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
Rewards Points if useful..
Regards,
N.Jayanth Kumar -
ISetup new custom interface using BC4J/java class
Hi,
I am able to create new custom interface using the link :- How to setup an user to be Oracle iSetup Super user ? but I have not seen anything for BC4J filter set, as per oracle iSetup developer guide clearly explains step by step process how to create custom BC4J interface type, but they have not mention how to add filters, as per oracle developer guide we have to use 'iSetup Framework' for BC4J, if we select type as 'iSetup Framework' then we don't have option to add filter parameters.
Any idea how to see existing iSetup interface repository values, Search shows the result, but we can't go in details? any idea to see this?
Oracle have good interface repository but most of them does not have option to filter, and update so I want to customize them by adding new interfaces with filterable and update option
Regards
AnilFirst, be sure your properties file is in the root of the classpath.
The Messages.properties or Messages_en.properties should be in the WEB-INF/classes/ directory of the war or as a root file of a jar included in the classpath (WEB-INF/lib).
If it doesn't work, try adding a "/" before the file name. The classloader will try to find it as a root file of the classpath.
For example:
ResourceBundle messages = ResourceBundle.getBundle("/Messages", locale);
If you are using sun appserver, the classloader hierarchy is configured by default from inside the war to outside, so it will search first in the WEB-INF/classes/Messages_en.properties and then it will search the file inside each jar file in WEB-INF/lib.
If you want more information, check the classloader hierarchy of the appserver you are using.
Hope it helps. -
Using Listeners, Newer to Java.
I've made a simple tic-tac-toe game, but I'm improving my code. Right now I have to type in coordinates to add my X, and I play against the computer.
My question is, how can I add a listener to one of the squares, so that when I click it, it adds an X.
If I knew how to do it with one square, I think I can conquer the rest.
So right now, I have one square displayed. All I want my program to do is to add an X inside of it, when I click it. Thats all.
Any tips? Any Help?
I'm quite new to Java. Like said, I have the square drawn already, but now I want it to add an X if I click anywhere inside the square.
Any help will be much appreciated. I've already got listeners and everything set up, I just don't know how to add the listener to the square. I can't post my code on here, because my other computer(the one where the code is) doesn't have internet access.
Thank you all in advance.
PirateXingimport java.awt.Point;
import java.awt.event.*;
public class LineListener implements MouseListener{
private Point current;
public void mouseClicked(MouseEvent event){
current=event.getPoint();
public void mousePressed(MouseEvent event) {
public void mouseReleased(MouseEvent event) {
public void mouseEntered(MouseEvent event) {
public void mouseExited(MouseEvent event) {
public int getX(){
return current.x;
public int getY(){
return current..y;
public class tictactoeboard extends JPanel{
public tictactoeboard(){
LineListener listener=new LineListener();
simpleshapes s=new simpleshapes("tictactoe");
drawSquare(50,50,50);
addMouseListener(listener);
if(listener.getX()>25&&listener.getX()<=50&&listener.getY()>=25&&listener.getY()<=50){
s.drawLine(25,25,75,75);
s.drawLine(75,25,25,75);
public void drawSquare(int x, int y, int sf){
simpleshapes s=new simpleshapes("tictactoe");
s.drawLine(x,y,x+sf,y);
s.drawLine(x,y,x,y+sf);
s.drawLine(x+sf,y,x+sf,y+sf);
s.drawLine(x,y+sf,x+sf,y+sf);
public void paintComponent(Graphics g){
super.paintComponent(g);
for(int i = 0; i < numLines;++i){
g.drawLine(lines[0],lines[i][1],lines[i][2],lines[i][3]);
for(int i = 0; i < numOvals;++i){
g.drawOval(ovals[i][0],ovals[i][1],ovals[i][2],ovals[i][3]);
public void addLine(short x1, short y1, short x2, short y2){
lines[numLines][0] = x1;
lines[numLines][1] = y1;
lines[numLines][2] = x2;
lines[numLines][3] = y2;
++numLines;
public void addOval(short x, short y, short w, short h){
ovals[numOvals][0] = x;
ovals[numOvals][1] = y;
ovals[numOvals][2] = w;
ovals[numOvals][3] = h;
++numOvals;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
tictactoeboard t=new tictactoeboard();
JFrame frame=new JFrame("OK");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new tictactoeboard());
I'm really embarrassed by this code, because I know its hard to read. But thats it, Its displaying the square quite well, I just want to put an X in it when I click inside of it. Thats the only thing I'm having problems with.
Thanks,
Pirate. -
How can I open help file (HTML or .chm) from Java Web Start (new to JAVA)
Hi All,
Im trying to open the help file of my application.
When trying to access the help file from the GUI (pressing F1 for launching the help file), I'm geting the an error, something like:
"Can't show help URL: jar:file:C:\Documents and Settings\%USER%\Application Data\Sun\Java\Deployment\javaws\cache\http\Dlocalhost\P7001\DMwebstart\RMjar-name!/com/resources/helpFiles/MyHelpFile.html"
It seems that the file which is packed in a jar, was downloaded to the Java Web Start cache directory:
C:\Documents and Settings\%USER%\Application Data\Sun\Java\Deployment\javaws\cache\http\Dlocalhost\P7001\DMwebstart
The code which is activated when launching the help file is:
try
ResourceBundle resourceBundle = DoubleResourceBundle.getBundle("Resource", "ResourceImpl");
RuntimeUtil.launchFile(new File(resourceBundle.getString("help.file")));
} catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
}where the property "help.file" is in some property file in the resource bundle named "Resource", and looks like this :
help.file="com/trax/docs/help/global/MyHelpFile.html"
The function "RuntimeUtil.launchFile" knows how to launch any file in its default application, and indeed it does launches the html, when giving it an absolute path to the file on my PC, as "C:\Helpfiles\MyHelpFile.html" as such:
RuntimeUtil.launchFile("C:\Helpfiles\MyHelpFile.html");My question is :
The application is going to be deployed on a Customer PC. How can I access the html file from the code, with a relative path and not its absolute path on the customer pc, which I can't know?
I found these restrictions regarding web start:
(copied from "http://rachel.sourceforge.net/"):
*Rule 1: Java Archives only. No loose files.* All your resources have to be packaged in Java Archives (jar) if you want to have
them delivered to the user's machine and kept up-to-date automatically by Java Web Start.
*Rule 2: No file paths.* You can't use absolute or relative file paths to locate your
jars holding your resources (e.g. <code>jar:file:///c:/java/jws/.cache/resources.jar</code>).
Absolute file paths won't work because you never know where Java Web Start
will put your jar on the user's machine. Relative file paths won't work because Java Web Start
mangles the names of your jars (e.g. <code>venus.jar</code> becomes <code>RMvenus.jar</code>)
and every JNLP client implementation has the right to mangle your names
in a different way and you, therefore, can't predict the name with
which your jar will be rechristend and end up on the user's machine in
the application cache.Seems complex or impossible, to perform a simple task like opening a file.
Please advise (I'm new to Java and Web Start).
BTW, I'm working with IntelliJ IDEA 5.0.
Thanks,
Zedik.
{font:Tahoma}{size:26pt}
{size}{font}the follwing method i have used to open html file ...
so to access html file i am shipping resources folder with jar file ..
private void openHtmlPages(String pageName) {
String cmd[] = new String[2];
String browser = null;
File file = null;
if(System.getProperty("os.name").indexOf("Linux")>-1) {
file = new File("/usr/bin/mozilla");
if(!file.exists() ) {
}else {
browser = "mozilla";
}else {
browser = "<path of iexplore>";
cmd[0] = browser;
File files = new File("");
String metaData = "/resources/Help/Files/"+pageName+".html"; // folder inside jar file
java.net.URL url = this.getClass().getResource(metaData);
String fileName = url.getFile();
fileName = fileName.replaceAll("file:/","");
fileName = fileName.replaceAll("%2520"," ");
fileName = fileName.replaceAll("%20"," ");
fileName = fileName.replaceAll("jarfilename.jar!"," ").trim();
cmd[1] = fileName;
try{
Process p = Runtime.getRuntime().exec(cmd);
}catch(java.io.IOException io){
//Ignore
can anyone give me the solution..???
Regards
Ganesan S -
Dear Forummembers,
I am student doing postgraduate studies in IT.i have some queries related to one of my programming staff.i am very much new into Java programming and i am finding it a bit difficult to handle this program.The synopsis of the program is given below -
You are required to design and code an object-oriented java program to process bookings for a theatre perfomance.
Your program will read from a data file containing specifications of the performance,including the names of the theatre, the play and its author and the layout of the theatre consisting of the number of seats in each row.
It will then run a menu driven operation to accept theatre bookings or display the current
status of seating in the theatre.
The name of the file containing the details of the performance and the theatre should be
provided at the command line, eg by running the program with the command:
java Booking Theatre.txt
where Theare.txt represents an example of the data file.
A possible data file is:
Opera
U and Me
Jennifer Aniston
5 10 10 11 12 13 14
The data provided is as follows
Line 1
Name of the Theatre
Line 2
Name of the play being performed
Line 3
Name of the author of the play being performed
Line 4
A list of the lengths (number of seats) of each row in the theatre, from front to
back.
The program must start by reading this file, storing all the appropriate parameters and
establishing an object to accept bookings for this performance with all details for the theatre
and performance.
The program should then start a loop in which a menu is presented to the user, eg:
Select from the following:
B - Book seats
T - Display Theatre bookings
Q - Quit from the program
Enter your choice:
And keep performing selected operations until the user�s selects the quit option, when the
program should terminate.
T - Display Theatre bookings
The Display Theatre Bookings option should display a plan of the theatre. Every available
seat should be displayed containing its identification, while reserved seats should contain an
Rows in each theatre are indicated by letters starting from �A� at the front. Seats are
numbered from left to right starting from 1. A typical seat in the theatre might be designated
D12, representing seat 12 in row D.
B - Book seats
The booking of seats is to offer a number of different options.
First the customer must be asked how many adjacent seats are
required. Then start a loop offering a further menu of choices:
Enter one of the following:
The first seat of a selected series, eg D12
A preferred row letter, eg F
A ? to have the first available sequence selected for you
A # to see a display of all available seats
A 0 to cancel your attempt to book seats
Enter your selection:
1. If the user enters a seat indentifier such B6, The program should attempt to
reserve the required seats starting from that seat. For example if 4 seats are
required from B6, seats B6, B7, B8 and B9 should be reserved for the customer,
with a message confirming the reservation and specifying the seats reserved..
Before this booking can take place, some testing is required. Firstly, the row
letter must be a valid row. Then the seat number must be within the seats in the
row and such that the 4 seats would not go beyond the end of the row. The
program must then check that none of the required seats is already reserved.
If the seats are invalid or already reserved, no reservation should be made and the
booking menu should be repeated to give the customer a further chance to book
seats.
If the reservation is successful, return to the main menu.
2. The user can also simply enter a row letter, eg B.IN this case, the program should
first check that the letter is a valid row and then offer the user in turn each
adjacent block of the required size in the specified row and for each ask whether
the customer wants to take them. Using the partly booked theatre layout above, if
the customer wanted 2 seats from row B, the customer should be offered first:
Seats B5 to B6
then if the customer does not want them:
Seats B10 to B11
and finally
Seats B11 to B12
If the customer selects a block of seats, then return to the main menu. If none are
selected, or there is no block of the required size available in the row, then report
that no further blocks of the required size are available in the row and repeat the
booking menu.
3. If the user enters a ? the program should offer the customer every block of seats
of the required size in the whole theatre. This process should start from the first
row and proceed back a row at a time. For example, again using the partially
booked theatre shown above, if the user requested 9 seats, the program should
offer in turn:
Seats A1 to A9
Seats C1 to C9
Seats C2 to C10
Seats E3 to E11
Seats E4 to E12
If the customer selects a block of seats, then return to the main menu. If none are
selected, or there is no block of the required size available in the whole theatre,
then report that no further blocks of the required size are available and repeat the
booking menu.
4. If the user enters a # the program should display the current status of the seating
in the theatre, exactly the same as for the T option from the main menu and then
repeat the booking menu.
5. If the user enters a 0 (zero), the program should exit from the booking menu back
to the main menu. If for example the user wanted 9 seats and no block of 9 was
left in the theatre, he would need to make two separate smaller bookings.
The program should perform limited data validation in the booking process. If a single
character other than 0, ? and # is entered, it should be treated as a row letter and then tested
for falling within the range of valid rows, eg A to H in the example above. Any invalid row
letters should be rejected.
If more than one character is entered, the first character should be tested as a valid row letter,
and the numeric part should be tested for falling within the given row. You are NOT
required to test for valid numeric input as this would require the use of Exception handling.
You are provided with a class file:
Pad.java
containing methods that can be used for neat alignment of the seat identifiers in the theatre
plan.
File Processing
The file to be read must be opened within the program and if the named file does not exist, a
FileNotFoundException will be generated. It is desirable that this Exception be caught and
a corrected file name should be asked for.
This is not required for this assignment, as Exception handling has not been covered in this
Unit. It will be acceptable if the method simply throws IOException in its heading.
The only checking that is required is to make sure that the user does supply a file on the
command line, containing details of the performance. This can be tested for by checking the
length of the parameter array args. The array length should be 1. If not, display an error
message telling the user the correct way to run the program and then terminate the program
System.exit(0);
The file should be closed after reading is completed.
Program Requirements
You are expected to create at least three classes in developing a solution to this problem.
There should be an outer driving class, a class to represent the theatre performance and its
bookings and a class to represent a single row within the theatre.
You will also need to use arrays at two levels. You will need an array of Rows in the Theatre
class.
Each Row object will need an array of seats to keep track of which seats have been reserved.
Your outer driving class should be called BookingOffice and should be submitted in a file named BookingOffice.java
Your second, third and any additional classes, should be submitted in separate files, each
class in a .java file named with the same name as the class
I am also very sorry to give such a long description.but i mainly want to know how to approach for this program.
also how to designate each row about it's column while it is being read from the text file, how to store it, how to denote first row as row A(second row as row B and so on) and WHICH CLASS WILL PERFORM WHICH OPERATIONS.
pls do give a rough guideline about designing each class and it's reponsibilty.
thanking u and looking forward for your help,
sincerely
RKyes i do know that........but can u ppl pls mention
atleast what classes shud i consider and what will be
the functions of each class?No, sorry. Maybe somebody else will, but in general, this is not a good question for this forum. It's too broad, and the question you're asking is an overall problem solving approach that you should be familiar with at this point.
These forums are best suited to more specific questions. "How do I approach this homework?" is not something that most people are willing or able to answer in a forum like this. -
New to JAVA, but old school to programming
Objects & Classes & Methods, Oh my!
I'm pretty new to java, but I've been programming in several languages over the years. I thought it was about time to update my skill set, especially with the job market as it is today. I wanted to go JAVA because it's not specific to any environment.
I picked up a begining JAVA book and was a little confused. When I was learning programming a program was called a program. a peice of code in a program called by a statement was called a subroutine (it was performed then control returned to the calling line and continued).
Now I'm trying to make sense of everything I have read so far and trying to relate it back to my old school of thinking. I was hoping it would make it easier to retain and I could expand it as I learn and possibly realize that it IS different. I know it's a new way of thinking, but stay with me for minute.
What I used to call a program is now a CLASS in JAVA (this can be a collection of code or other objects). A sub-routine in a CLASS is a Method. I know that the language part will come as I use it since I understand if's then's and whatever you use to gosub or goto, but I want to make sure I have down the lingo before I go to deep.I have no idea how you can compare Java to Cobol.
DataFlex? How about that! In about '84 I switched to
DataFlex from dBaseII. In '91 DataFlex changed from
procedural to OOP. It took most of us at least a year
to adjust, and then some to write concrete code. It
was tough. They had bugs and we were limited with DOS.
BUT, it was a great OOP training experience. Anyhow,
needless to day Java is miles ahead on all fronts.Small world. I was stuck in the old DataFlex Ver 2.3 at that time. The company I worked for had the newer OOP package. I did get to work with it some, but not enough to become totally familiar with it. We started to move out of DataFlex towards PowerBuilder towards the end of 1995. I did get some OOP from that experience, but again only enough to learn about global variables, instance variables, and a few other items. I hoping that I will be able to get the solid OOP background that I need from JAVA since I hear through the grapevine that it may be a new tool that we will be looking at to enhance our programming. I was looking at PERL but even the PERL programmers we have agree that JAVA is more scalable. -
New to Java and need help with this program..please!
I'd really appreciate any helpful comments about this program assignment that I have to turn in a week from Friday. I'm taking a class one night a week and completely new to Java. I'd ask my professor for help, but we can't call him during the week and he never answers e-mails. He didn't tell us how to call from other classes yet, and I just can't get the darn thing to do what I want it to do!
The assignment requirements are:
1. Change a card game application that draws two cards
and the higher card wins, to a Blackjack application
2. Include a new class called Hand
3. The Hand class should record the number of draws
4. The application should prompt for a number of draws
5. The game is played against the Dealer
6. The dealer always draws a card if the dealer's hand total is <= 17
7. Prompt the player after each hand if he wants to quit
8. Display the total games won by the dealer and total and the total games wond by the player after each hand
9. Display all of the dealer's and player's cards at the
end of each hand
10. Player has the option of drawing an additional card after the first two cards
11. The Ace can have a value of 11 or 1
(Even though it's not called for in the requirements, I would like to be able to let the Ace have a value of 1 or an 11)
The following is my code with some comments about a few things that are driving me nuts:
import java.util.*;
import javax.swing.*;
import java.text.*;
public class CardDeck
public CardDeck()
deck = new Card[52];
fill();
shuffle();
public void fill()
int i;
int j;
for (i = 1; i <= 13; i++)
for (j = 1; j <= 4; j++)
deck[4 * (i - 1) + j - 1] = new Card(i, j);
cards = 52;
public void shuffle()
int next;
for (next = 0; next < cards - 1; next++)
int rand = (int)(Math.random()*(next+1));
Card temp = deck[next];
deck[next] = deck[rand];
deck[rand] = temp;
public final Card draw()
if (cards == 0)
return null;
cards--;
return deck[cards];
public int changeValue()
int val = 0;
boolean ace = false;
int cds;
for (int i = 0; i < cards; i++)
if (cardValue > 10)
cardValue = 10;
if (cardValue ==1) {
ace = true;
val = val + cardValue;
if ( ace = true && val + 10 <= 21 )
val = val + 10;
return val;
public static void main(String[] args)
CardDeck d = new CardDeck();
int x = 3;
int i;
int wins = 1;
int playerTotal = 1;
do {
Card dealer = (d.draw());
/**I've tried everything I can think of to call the ChangeValue() method after I draw the card, but nothing is working for me.**/
System.out.println("Dealer draws: " + dealer);
do {
dealer = (d.draw());
System.out.println(" " + dealer);
}while (dealer.rank() <= 17);
Card mine = d.draw();
System.out.println("\t\t\t\t Player draws: "
+ mine);
mine = d.draw();
System.out.println("\t\t\t\t\t\t" + mine);
do{
String input = JOptionPane.showInputDialog
("Would you like a card? ");
if(input.equalsIgnoreCase("yes"))
mine = d.draw();
System.out.println("\t\t\t\t\t\t" + mine);
playerTotal++;
else if(input.equalsIgnoreCase("no"))
System.out.println("\t\t\t\t Player stands");
else
System.out.println("\t\tInvalid input.
Please try again.");
I don't know how to go about making and calling a method or class that will combine the total cards delt to the player and the total cards delt to the dealer. The rank() method only seems to give me the last cards drawn to compare with when I try to do the tests.**/
if ((dealer.rank() > mine.rank())
&& (dealer.rank() <= 21)
|| (mine.rank() > 21)
&& (dealer.rank() < 22)
|| ((dealer.rank() == 21)
&& (mine.rank() == 21))
|| ((mine.rank() > 21)
&& (dealer.rank() <= 21)))
System.out.println("Dealer wins");
wins++;
else
System.out.println("I win!");
break;
} while (playerTotal <= 1);
String stop = JOptionPane.showInputDialog
("Would you like to play again? ");
if (stop.equalsIgnoreCase("no"))
break;
if (rounds == 5)
System.out.println("Player wins " +
(CardDeck.rounds - wins) + "rounds");
} while (rounds <= 5);
private Card[] deck;
private int cards;
public static int rounds = 1;
public int cardValue;
/**When I try to compile this nested class, I get an error message saying I need a brace here and at the end of the program. I don't know if any of this code would work because I've tried adding braces and still can't compile it.**/
class Hand()
static int r = 1;
public Hand() { CardDeck.rounds = r; }
public int getRounds() { return r++; }
final class Card
public static final int ACE = 1;
public static final int JACK = 11;
public static final int QUEEN = 12;
public static final int KING = 13;
public static final int CLUBS = 1;
public static final int DIAMONDS = 2;
public static final int HEARTS = 3;
public static final int SPADES = 4;
public Card(int v, int s)
value = v;
suit = s;
public int getValue() { return value; }
public int getSuit() { return suit; }
public int rank()
if (value == 1)
return 4 * 13 + suit;
else
return 4 * (value - 1) + suit;
/**This works, but I'm confused. How is this method called? Does it call itself?**/
public String toString()
String v;
String s;
if (value == ACE)
v = "Ace";
else if (value == JACK)
v = "Jack";
else if (value == QUEEN)
v = "Queen";
else if (value == KING)
v = "King";
else
v = String.valueOf(value);
if (suit == DIAMONDS)
s = "Diamonds";
else if (suit == HEARTS)
s = "Hearts";
else if (suit == SPADES)
s = "Spades";
else
s = "Clubs";
return v + " of " + s;
private int value; //Value is an integer, so how can a
private int suit; //string be assigned to an integer?
}Thank you so much for offering to help me with this Jamie! When I tried to call change value using:
Card dealer = (d.changeValue());
I get an error message saying:
Incompatible types found: int
required: Card
I had my weekly class last night and the professor cleared up a few things for me, but I've not had time to make all of the necessary changes. I did find out how toString worked, so that's one question out of the way, and he gave us a lot of information for adding another class to generate random numbers.
Again, thank you so much. I really want to learn this but I'm feeling so stupid right now. Any help you can give me about the above error message would be appreciated. -
New to java: how to replace an image extending a JComponent?
Hi,
I'm new to Java and I have a question about Swing:
I have a class called ActiveImage (entends JComponent, implements MouseMotionListener, MouseWheelListener) which takes an Image and displays it. It also receives some mouse events for zooming and moving it around. I display it in a JFrame using:
content = getContentPane();
content.setLayout(new BorderLayout());
image = toolkit.getImage (filename);
ActiveImage activeImage = new ActiveImage(image);
content.add(activeImage, BorderLayout.CENTER);
(This code is in a class extending JFrame.)
This works fine. However, this JFrame also contains a JToolbar with two buttons. Now when I click one of them, I want to replace the image with another one. I've tried removing it and creating a new ActiveImage to add that to content, but that didn't work very well. remove() resulted in a NullPointerException.
My question: what would be the best way to go about this?
Many thanks for any help,
Diederick de VriesB.T.W., this is the trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ActiveImage.ActiveImageFrame$1.actionPerformed(ActiveImageFrame.java:60)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1766)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)Just before this, it says "button clicked". The function that calls the setImage() goes:
theButton.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("button clicked");
activeImage.setImage(image);
});Reading the trace, I would think that the exception has something to do with this last code, since it stops there (line 60 is the setImage()). If the setImage() function itself was where the fault was, wouldn't the trace end there?
I'm really at a loss here ... :-( -
How can i add custom attributes to a new Class Object using the API ?
Hello everyone,
Here is my problem. I just created a subclass of Document using the API (not XML), by creating a ClassObjectDefinition and a ClassObject. Here is the code :
// doc is an instance of Document
ClassObject co = doc.getClassObject();
ClassObjectDefinition cod = new ClassObjectDefinition(ifsSession);
cod.setSuperclass(co);
cod.setSuperclassName(co.getName());
cod.setName("MYDocument");
ClassObject c = (ClassObject)ifsSession.createSchemaObject(cod);
Everything seems to be OK since i can see the new class when i use ifsmgr. But my question is : how can i add custom attributes to this new class ? Here is what i tried :
AttributeDefinition value = new AttributeDefinition(ifsSession);
value.setAttribute("FOO", AttributeValue.newAttributeValue("bar"));
c.addAttribute(value);
But i got the following error message :
oracle.ifs.common.IfsException: IFS-30002: Unable to create new LibraryObject
java.sql.SQLException: ORA-01400: impossible d'insirer NULL dans ("IFSSYS"."ODM_ATTRIBUTE"."DATATYPE")
oracle.ifs.server.S_LibraryObjectData oracle.ifs.beans.LibrarySession.DMNewSchemaObject(oracle.ifs.server.S_LibraryObjectDefinition)
oracle.ifs.beans.SchemaObject oracle.ifs.beans.LibrarySession.NewSchemaObject(oracle.ifs.beans.SchemaObjectDefinition)
oracle.ifs.beans.SchemaObject oracle.ifs.beans.LibrarySession.createSchemaObject(oracle.ifs.beans.SchemaObjectDefinition)
void fr.sword.ifs.GestionDocument.IFSDocument.createDocument(java.lang.String)
void fr.sword.ifs.GestionDocument.IFSDocument.main(java.lang.String[])
So, what am i doing wrong ?
More generally, are we restricted in the types of the attributes ? (for example, would it be possible to add an attribute that would be an inputStream ? Or an object that i have already created ?).
Any help would be appreciated. Thanks in advance.
Guillaume
PS : i'm using Oracle iFS 1.1.9 on NT4 SP6 and Oracle 8.1.7
nullHi Guillaume,
you're welcome. Don't know exactly, but assume that ATTRIBUTEDATATYPE_UNKNOWN
is used to check for erronous cases only
and it shouldn't be used otherwise.
Creating your own objects could be simply done via
ClassObject ifsClassObject;
DocumentDefinition ifsDocDef = new DocumentDefinition(ifsSession);
// get class object for my very own document
ifsClassObject = ClassObject.getClassObjectFromLabel(ifsSession, "MYDOCUMENT");
// set the class for the document i'd like to create
ifsDocDef.setClassObject(ifsClassObject);
// set attributes and content for the document...
ifsDocDef.setAttribute("MYFOO_ATTRIBUTE",....);
ifsDocDef.setContent("This is the content of my document");
// create the document...
PublicObject doc = ifsSession.createPublicObject(ifsDocDef);
null -
How to create new XML file using retreived XML content by using SAX API?
hi all,
* How to create new XML file using retreived XML content by using SAX ?
* I have tried my level best, but output is coming invalid format, my code is follows,
XMLFileParser.java class :-
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;
public class PdfParser extends XMLFilterImpl {
private TransformerHandler handler;
Document meta_data;
private StringWriter meta_data_text = new StringWriter();
public void startDocument() throws SAXException {
void startValidation() throws SAXException {
StreamResult streamResult = new StreamResult(meta_data_text);
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try
handler = factory.newTransformerHandler();
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
handler.setResult(streamResult);
handler.startDocument();
catch (TransformerConfigurationException tce)
System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
super.startDocument();
public void startElement(String namespaceURI, String localName,
String qualifiedName, Attributes atts) throws SAXException {
handler.startElement(namespaceURI, localName, qualifiedName, atts);
super.startElement(namespaceURI, localName, qualifiedName, atts);
public void characters(char[] text, int start, int length)
throws SAXException {
handler.characters(text, start, length);
super.characters(text, start, length);
public void endElement(String namespaceURI, String localName,
String qualifiedName) throws SAXException {
super.endElement("", localName, qualifiedName);
handler.endElement("", localName, qualifiedName);
public void endDocument() throws SAXException {
void endValidation() throws SAXException {
handler.endDocument();
try {
TransformerFactory transfactory = TransformerFactory.newInstance();
Transformer trans = transfactory.newTransformer();
SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
DOMResult dom_result = new DOMResult();
trans.transform(sax_source, dom_result);
meta_data = (Document) dom_result.getNode();
System.out.println(meta_data_text);
catch (TransformerConfigurationException tce) {
System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
catch (TransformerException te) {
System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
} CreateXMLFile.java class :-
Sax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
* In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
is not an XML type text, it just an Normal text Why that ?
* Please help me what is the problem in my code?
Cheers,
JavaImranSax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
</code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
<code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
* I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
* I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
Thanks,
JavaImran{code} -
Oracle 10g - Creating a new Application Server using standalone OC4J 10g
I have some issues in creating a new app. server using standalone oc4j 10g 10.1.3 instance. After I created the app. server instance, I tested the connection and it says connection refused. I used the userid as oc4jadmin and the password as welcome. I am getting a message connection refused. For connection, I used the default hostname "localhost" and I didn't mention anything in the URL path.
Thanks Steve..
Here is what I am trying to do.. I want to create a new app server instance (i.e.) stand alone oc4j server, where I can deploy my web service and run a test.
Oracle JDeveloper 10g:
Under Connection Navigator, Application Server --
1) Right click to 'Create New Application Server Connection'
2) Connection type as 'Standalone OC4J 10 g 10.1.3',
3) Username ==> oc4jadmin, Password ==>welcome, checked the Deploy password.
4) Hostname: localhost RMI Port: 23791
URL path: <<blank>>
5) Test Connection ==> getting a error message...
Error while getting remote MBeanServer for url: ormi://localhost:23791/default:
Error reading application-client descriptor: Error communicating with server: Connection refused: connect; nested exception is:
javax.naming.CommunicationException: Connection refused: connect [Root exception is java.net.ConnectException: Connection refused: connect]
Any input you can provide would be of great help.
Maybe you are looking for
-
Ok, i know this been asked a few times before in this forum but none have a imo definitve answer to this.I hope someone could help me.Sometime It's quite frustating that i was unable to launch pixel bender unless i disable the card drivers to use the
-
Application errors occured in ccBPM not restartable?
hello experts, We are using ccBPM for some of the integration scenarios and synchronously posting data to SAP R/3. When an BAPI returns an application error code (e.g. material locked by an user), we are unable to restart these messages from SXMB_MON
-
HTMLLoader loading local content (SWF files) problem
Hello guys, I'm just finishing my application but I facing a problem. I'm currently developing a desktop application using AIR. I'm using HTMLLoader to load local SWF files when te user tries to access specific content on the application. I successfu
-
Merging List Items with Word Template
Hello, I'm running SharePoint 2013, SharePoint Designer 2013 and the latest versions of Word and Windows. I'm not a programmer of any sorts. I want to run a workflow, triggered by the addition of a new list item. The workflow needs to take the new
-
Please open this link before reading http://download.oracle.com/docs/cd/B28196_01/idmanage.1014/b25347/osso.htm#BJFJEJEJ I want to enable SSO in oracle access manager to integrate it with oracle application manager. I already did the previous steps f