you might want to play around with the DecimalFormat class some, if you want your numbers to have commas after every three numbers and an % before or after your numbers.
you might want to play around with the DecimalFormat class some, if you want your numbers to have commas after every three numbers and an % before or after your numbers.
The % is a sign for modular division in java.
Thank you guys very much, you were both a big help...
I started learning about it a while back, but each time I learn something about it, I find myself going back to 1.4. I thought the generics were pretty cool. At my school, we use 1.4, and half of my programs won't work on their machines, so I have to wind up converting it back to 1.4. It just seems to me that everyone is sticking to 1.4.
I'm curious as to how many of you routinely use jdk 1.5 tigers added features, methods, api's and whatever. Or, do you just stick to 1.4?
drawOval(int x, int y, int width, int height)
Just use threads to increment the x and y value position at certain intervals.
This is what I'm trying right now, but it's not working..
public File PathStart()
{
for (char dirs='A'; dirs >= 'Z'; dirs++)
{
File path = new File(dirs + "://");
if (path.isDirectory())
{
startingPath = path;
System.out.println(startingPath.toString());
}
}
return startingPath;
}
Ok, I found out how to search. Now the only thing I need to know is, how do you find out what the users root directory is?
I know how to find a directory if I know the full path name of the directory I'm searching for..But, let's say I only know the directory name, and not the full path name..How can I find that directory on a users system? Is there some recursive function or looping structure to achieve this?
If you use an ArraList like jwenting suggested, you can use:
Collections.sort(ArrayList);
You might could use that on a vector, but I doubt it. Never tried.
Also, isn't there some way to use the comparator interface to sort?
Im curious, why do you create an instance of the class in each method?
CurrencyConv2 a1 = new CurrencyConv2();
How come you prompt the user for amount in pennies?
Thanks server_crash,
I have read this discussion and it is very helpful. But I think this discussion is not similar to my issue. My issue is that the sound can not be played, and the discussion is dealing with how to solve delay issue (the sound can be played in this discussion). I am wondering your comments.
regards,
George
I knew it was a little different, but I was hoping you could use their methods of playing sound in your app.
Check out this:
http://www.javakb.com/Uwe/Forum.aspx/java-programmer/14139/re-playing-sound-in-J2ME
I don't know if this will help or not. I haven't had any experience working with j2me either.
If you simply want to play a .wav file, there are much simplier ways of doing this. That is of course, if your wanting to do this on a pc....
You already have a bunch of values that represent the currency amounts. The best thing to do, would be store these in an array, and then start calculating them through a loop. I know this is possible, because I have AP Comp Sci, and had this same project except ours had to include a gui, and some other advanced things.
In your main method, you call some method, but for some reason that method also creates another instance of the class your already in and continues from there. I think you should put this all under the main method, and maybe it won't be so confusing for you.
public static void main(String[] args) {
try {
Player player = [B]Manager.createPlayer"http://localhost/sample.wav");[/B]
player.start();
} catch (MediaException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
could the problem be leaving out a parenthesis?
public static void main(String[] args) {
try {
Player player = Manager.createPlayer("http://localhost/sample.wav");
player.start();
} catch (MediaException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
It can be used as a recursive function. I guess that's what he was talking about...Maybe...?
int a = 5;
int b = 7;
if (a > b)
{
b += 1;
}
else
{
b -= 1;
}
Is this what your talking about?
Maybe if I have time I'll look at it, but right now I don't.
You really need to work on how it's written.
I was afraid they would change it every day...Since I was just going to do this for fun, I guess I won't worry about it. As you said, it's probably the equivilent of stealing..
Thanks for all your help.
what about reading the source code of the web site using a url connection..I think you could get the info you want like that, but it would probably be very hard..What do you think?
it's not static.
It MUST have the exact signature:
public static void main(String[] args) //you can call the string array whatever
{
}
you forgot the main method:
public static void main(String[] args)
{
}
Thank very much. That was EXTREMELY helpful. I checked out this one site, and it turns out you do have to pay for it.
Is it possible to update your programs information from other websites? I mean if you have like a stock program or currency program, the data changes everyday. So can you recieve updates from websites, and change this info? If so could you point me to a site that explains how, or some kind of api that can achieve this?
Thanks Christian, very helpful relpy!
Here is my classpath: Note: Your's will probably be different.
.;%classpath%.;.;C\Program Files\Java\jdk1.5.0\lib\tools.jar
classpath should point to the tools.jar file
Here is what my path variable looks like:
C:\Program Files\Java\jdk1.5.0\bin
it just points to the bin folder.
Note: to set your environment variable, right click on the my computer icon, then select advanced, then at the bottom there will be something that says environment variables.
That's the problem with your purely linear way of doing things.
Create a parsetree and recursively process it from the inside out.
Yep, I knew the way I was doing would only allow two operands, but that's really all I could think of. I'll try the parsetree as you suggested..Sounds like something trivial, so I might have to come back for help!
Does anyone know how you could process an equation, or even get an equation with more than two operands? Right now, in my calculator, I can only have two operands, and I want to have more.
Right here is what I have:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener
{
JButton[] btnNums;
JButton btnBack;
JButton btnClear;
JButton btnCalculate;
String[] strNames;
String strOperand1;
String strOperand2;
Boolean wasClicked;
String answer;
double dd;
final String STR_MULTIPLY = "MULTIPLY";
final String STR_DIVIDE = "DIVIDE";
final String STR_ADD = "ADD";
final String STR_SUBTRACT = "SUBTRACT";
String whichOperator;
JTextField txtDisplay;
public Calculator()
{
Container content = getContentPane();
setSize(210,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* construct a JPanel and the textfield that
* will show the inputed values and outputed
* results
*/
JPanel jpDisplay = new JPanel();
jpDisplay.setLayout(new BorderLayout());
txtDisplay = new JTextField(15);
txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
jpDisplay.add(txtDisplay);
/* contstruct a JPanel that will contain a back
* button and a clear button.
*/
JPanel jpRow2 = new JPanel();
btnBack = new JButton("Backspace");
btnBack.addActionListener(this);
btnClear = new JButton("Clear");
btnClear.addActionListener(this);
btnClear.addActionListener(this);
jpRow2.add(btnBack);
jpRow2.add(btnClear);
/* construct a string array with all the names of the
* buttons, then in a for loop create the new buttons
* and add their name and an actionListener to them.
*/
String[] strNames = {"7","8", "9","/", "4", "5", "6","*", "1",
"2", "3","+", "0", "+/-", ".", "-"};
btnNums = new JButton[16];
JPanel jpButtons = new JPanel();
jpButtons.setLayout(new GridLayout(4,4));
for (int i = 0; i < 16; i++)
{
btnNums[i] = new JButton(strNames[i]); …
hmm. If I remember right, java doesn't support those file extensions. I think it supports weird ones like au, aiff, and stuff like that. But, I do think it supports .wav files.
Maybe someone will correct me if I'm wrong
Thank you guys. Both replys were helpful. I just wanted to know what other people that's been around it, thought about it. So thank you.
Thanks server_crash,
I am wondering how you debug your applications since you do not use log utility.
regards,
George
lol I never really did. Sometimes I used System.out.println()'s, and sometimes I just knew what to do from the error. I've never really created anything so big, that it require a lot of debugging. But, my text editor I'm working on right now is in need of it. So I might have to put it to some use.
I had no clue you could do that in java. I looked at some of the logging api's, and it looked very useful.
I think I might have to try it out. I'm stuck on JEdit, so I guess it will be good to try something new.
remember using the substring function that it also starts at index 0. So if you wanting to get the first character, I think you would do this:
menu_opt.substring(0,1);
and the second one :
menu_opt.substring(1,2);
As for the numeric data, I think it depends on your jdk version. In some you may be able to do this:
indata.readDouble();
some not.
You can always take the inputed string and convert it to a Double or int
int x = Integer.parseInt(string);
or
double d = Double.doubleValue(String);
PS: Don't be bothered about what narue said, some people simple refuse to help others out but when they need help they expect others to help them out.
I've seen it many times on here. You would think that some people would realize there is no need for a forum if you simply tell people to look on google. I guess it's just they don't know how to do it. The point of a forum is to help people.
I don't recall anything like that. I would either leave them, or remove them manually.
It does start at element or index 0. You only have one element in your array or [0]. You have a for loop trying to shove mulltiple things in an array with only one element. I'm not sure I understand what your wanting to do with the menu_Opt array.
never mind, I got it.
public void actionPerformed(ActionEvent ae)
{
for (int i =0; i < 16; i++)
{
if (ae.getSource() == btnNums[i])
{
txtDisplay.setText(txtDisplay.getText() + btnNums[i].getLabel());
}
}
}
instead of this:
public static void main(String[] args)
do this:
public static void main(String[] args) throws IOException
then it will compile
What's the scanf function? I'm not familar with C++..
I have this simple calculator I just started on, and I'm having just a few problems. First of all, I don't know how to append text to a textfield. Maybe I would have to create a string buffere or something. Then, when the user clicks one of the buttons, the compiler goes crazy, and nothing is displayed.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener
{
JButton[] btnNums;
JButton btnBack;
JButton btnClear;
JButton btnCalculate;
String[] strNames;
JTextField txtDisplay;
public Calculator()
{
Container content = getContentPane();
setSize(210,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* construct a JPanel and the textfield that
* will show the inputed values and outputed
* results
*/
JPanel jpDisplay = new JPanel();
jpDisplay.setLayout(new BorderLayout());
txtDisplay = new JTextField(15);
txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
jpDisplay.add(txtDisplay);
/* contstruct a JPanel that will contain a back
* button and a clear button.
*/
JPanel jpRow2 = new JPanel();
btnBack = new JButton("Backspace");
btnClear = new JButton("Clear");
btnClear.addActionListener(this);
jpRow2.add(btnBack);
jpRow2.add(btnClear);
/* construct a string array with all the names of the
* buttons, then in a for loop create the new buttons
* and add their name and an actionListener to them.
*/
String[] strNames = {"7","8", "9","/", "4", "5", "6","*", "1", "2", "3","+", "0", "+/-", ".", "-"};
btnNums = new JButton[16];
JPanel jpButtons = new JPanel();
jpButtons.setLayout(new GridLayout(4,4));
for (int i = 0; i < 16; i++)
{
btnNums[i] = new JButton(strNames[i]);
btnNums[i].addActionListener(this);
jpButtons.add(btnNums[i]);
}
/* construct the final JPanel and add a
* calculate button to it.
*/
JPanel jpLastRow = …
Yeah, it's the same way here. I was hoping to have a teacher that was a guru at java so I could learn a lot. But, I guess it's not all his fault.
What about this? It's probably not exactly what you want, but it will get you on your way.
import java.io.*;
public class HexToByteConverter{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while (!(line = br.readLine()).equals("")){
for (int i = 0,j = line.length(); i < j; i++){
System.out.print(Integer.toBinaryString(Character.digit(line.charAt(i),16)));
}
System.out.println();
}
}
}
Note: Area you using a DocumentRenderer for the printing of the JTextPane?
http://forum.java.sun.com/thread.jspa?threadID=587153
It's something about the offset is different.
I personally have never tryed to print in java. I've been working on this text editor and that is my next job, which I will hate!
I did search the java forums and found some people with similar problems, but unfortunately, no one posted with answers on any of the questions.
I found a link that looked like it my do you some good, but it might not. It looked like they were using something to count the pages and then using a book object declaring what was to be printed, and it looked like you could specify the number of pages to be printed. But I think what you wanted was the user selection.
http://www.javaworld.com/javaworld/jw-06-1999/jw-06-step.html
If it's the user selection you want printed, how are you getting the selected text and appending it to a printjob?
Does the print dialog even have an option for printing the selected text? I didn't see one on some of examples they had. This makes me wonder if you would have to print the selection without a dialog.
Note: I really don't know much about the printing, but hopefully some of the suggestions will help.