darkagn 315 Veteran Poster Featured Poster

Are you saying you want thousands of command prompts? What exactly are you trying to do in the exec line?

darkagn 315 Veteran Poster Featured Poster

System.in is the standard input stream that java supplies to get input from the console. I usually use code that looks like this:

BufferedReader input = new BufferedReader( new InputStreamReader( System.in ) );

Then use the readLine() method in the BufferedReader class to read each line of input. For more info, check out the java api.

darkagn 315 Veteran Poster Featured Poster

I'm not 100% sure, but I think this issue could have to do with threads. I think what is happening is the cmd.exe is being run in the main thread and there is no other thread to run the rest of class A until you quit the cmd.exe. If I am correct, you need to implement a third class like so:

public class C implements Runnable
{
  public void run()
  {
    Process p1 = Runtime.getRuntime().exec(...
  }
}

Next you need to modify class B like so:

startimport()
{
  C runnable = new C();
  new Thread( runnable ).start();
  sysout("here is output");
}

For more information on Threads, see the sun website.

darkagn 315 Veteran Poster Featured Poster

Hi bmbvm5 and welcome to DaniWeb,

Unfortunately we are not allowed to just do the work for you, we need to see some effort and then we can give pointers. What have you done so far? What problems are you having? Just giving us your assignment specification isn't enough sorry.

darkagn 315 Veteran Poster Featured Poster

http://en.wikipedia.org/wiki/Red_black_tree describes the difference in fairly good detail. The main difference between the two is in the worst case, where a BST can be as bad as O(n) for insertion, search and delete, but a red-black tree is O(log n) in the worst case for these operations. The article is well worth a read as it describes how the red-black tree maintains its balance.

darkagn 315 Veteran Poster Featured Poster

Ok, so what have you done so far? Or where exactly are you having problems? We can only point you in the right direction - we can't do it for you.

darkagn 315 Veteran Poster Featured Poster

Hi ladyjade555 and welcome to DaniWeb :)

Ok there are a couple of issues with our code that I can see with a quick read-through. Line 40 is

import java.lang.Math;

You don't need to explicitly import any classes or packages that start with java.lang - these are the classes that are automatically "imported" with the java virtual machine. They form the base classes that the other packages in java (including the ones that you write) build upon.

Lines 92-94 are probably the lines that are causing you grief when you attempt to compile. These lines are explicitly trying to set the variables in your Formal2 object, but you are doing it incorrectly. You can't access the variables directly from the Main class because the variables are not open to the "public". However you can call your "set" methods because they have been made public. For example, by changing line 92 to

l1.setName("Toronto");

you will set the name of your object to "Toronto" and this is legal. I'll let you work out how to set the longitude and latitude.

As an aside, it would probably be better to set the variables in a constructor method in the Formal2 class rather than the way that I have explained. However, that might be a little further down the track in your learning path, but I thought I'd mention it anyways.

Let me know how you go with my suggestions. :)

darkagn 315 Veteran Poster Featured Poster

Better yet, maybe just give us a brief overview of what your program does and we will try to guide you. If we need to see your code, we'll let you know :)

darkagn 315 Veteran Poster Featured Poster

The print function is O(n), so you were right the first time. Although n changes each call to print, it is still O(n) since each time print is called it takes roughly n steps to compute.

I'm not completely sure, but I think the second recursive call will also be O( n.log(1/n) ), since it basically does the same thing as the first recursive call. (That's assuming your logic was correct - I haven't checked it). So your overall algorithm is:
O( n.log(1/n) + n.log(1/n) )
= O( 2n.log(1/n) )

This is equivalent to O( n.log(1/n) ) since the constant '2' has little bearing over the time complexity as n -> infinity.

I hope that this helps, let me know if you need more explanation :)

darkagn 315 Veteran Poster Featured Poster

Hi all,

I am fairly new to using Eclipse (or any IDE for that matter) and I am having trouble getting the TPTP Profiler plugin working. I'm hoping that someone out there might have seen this behaviour before and has the fix for it... :) I am running Eclipse 3.3.1.1 with JRE 1.6.0_04 in Windows XP.

The problem is that when I select Profile As... > Java Application I get the error:
[Monitor]: The launch requires at least one data collector to be selected.
Eclipse then closes. I tried using the Profile Dialog to set the Monitor settings, but opening this screen also forces Eclipse to quit. :( I have tried searching for updates and installing new features but no joy. :angry:

I am at a complete loss as to what to try next. Any ideas?

Thanks in advance,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi all,

I was wondering if anyone had tried to use the Quicktime for Java platform to stream video in either MPEG-4 or MJPG formats? Can the platform be used in linux if it uses the third-party Quicktime for Linux?

Or is there another platform that might be suitable for this? Apparently the JMF is not supported anymore, but does anyone know of another way to stream video into a Java application?

Thanks in advance for any clues,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi Akeem Amure and welcome to Daniweb :)

A couple of things before we start - please don't shout (by using all capitals) and there is no need to ask for help as soon as possible as we always try to get back to you when we can. Also, please use code tags when posting chunks of source code as it makes it easier to read.

Ok, looking at your code there is a few things. The statement

import jav.awt.*;

automatically imports the class Graphics, so there is no need to import it explicitly. Also, you don't need to import anything starting with java.lang as this is the default package that gets imported automatically.

In answer to your question, the Graphics class has a series of methods beginning with fill, for example fillOval, which can be used to paint a shape with a filled colour. In order to outline the shape in a different colour, call the draw method after the fill method with a different colour.

Hope this helps :)
darkagn

darkagn 315 Veteran Poster Featured Poster

The java.awt.PrintJob class is what you need here. You create the PrintJob object and set the header, body and footer of what you want printed then tell it to print. For more information, check out the Java API for the PrintJob class.

darkagn 315 Veteran Poster Featured Poster

Perfect :)

darkagn 315 Veteran Poster Featured Poster

No problem :) You would be surprised though how many people confuse l and I in the println statement, so don't feel embarrassed. And we all started somewhere so feel free to ask as many questions as you need to learn - that's what this site is for.

All the best,
darkagn

darkagn 315 Veteran Poster Featured Poster

not In, ln - lowercase L followed by an n.

Otherwise perfect :)

darkagn 315 Veteran Poster Featured Poster

It is often confusing for C++ programmers to use print and println rather than printf. But personally I think the java way of doing things is much more intuitive once you get the hang of it. Stay in there and you will be fine :)

darkagn 315 Veteran Poster Featured Poster

Not quite. Notice my print statement above is

System.out.print

NOT printf.
Otherwise your statements are good, although technically you don't need the ""+ in the second one, you can just write

System.out.print(last_name);

and you might want to make the last one a println statement rather than print (to give a carriage return at the end of your line).

darkagn 315 Veteran Poster Featured Poster

System.out.printf("The weekly pay for %s", first_name); //display first name

should read:

System.out.print("The weekly pay for " + first_name); // display first name

I'll leave you to figure out the other two printf lines...

darkagn 315 Veteran Poster Featured Poster

Hi dharajsmith and welcome to Daniweb :)

Your System.out.printf lines are incorrect syntax in Java.

As an aside, please put code in code tags as it makes it easier to read.

darkagn 315 Veteran Poster Featured Poster
for (int i=0; i<n; i++)
int i=0;
(while i<n)

These two pieces of code are equivalent loops. But the while loop needs n steps to execute because the initialisation of i occurs outside the loop. The for loop requires n steps +1 to instantiate i inside the condition of the loop.

However in Big O notation, both are referred to as O(n) because constants have no effect on the trend as n approaches infinity. While Horowitz is technically correct, it is not in terms of algorithm complexity that they are talking about here - it is the number of programming steps (ie the number of operations the program executes). Number of operations is a bit of a misleading representation of program complexity, as I have shown in the above code.

darkagn 315 Veteran Poster Featured Poster

For your previous button, I think you want to do something like

index--;
if (index < 0) {
   index = numItems - 1;
}

This will allow you to cycle through your inventory items by pressing the Previous button when you are at the first item. You can do the opposite with the Next button to cycle through when you hit Next at the last item in the list.

For your logo, I think you will need to use the java.awt.image package.

darkagn 315 Veteran Poster Featured Poster

Hi there fm_hyudin and welcome to Daniweb,

We are not allowed to help you until you show us that you have made an effort to answer the question yourself. What have you done so far?

darkagn 315 Veteran Poster Featured Poster

That error normally occurs when you try to run the java class file without having first compiled it. The correct (two) commands are:

javac E:\Chap1\source.java
java E:\Chap1\source

As far as I know it shouldn't matter where your files are located if you provide the full path.

darkagn 315 Veteran Poster Featured Poster

You will need to call singleton.getInstance() somewhere in your main method to get the instance of the class. Call it twice to see if you can only create one instance.

darkagn 315 Veteran Poster Featured Poster

Put an else statement in your getInstance method that reads

System.out.println("Hey, I'm already created!!");

then try calling getInstance twice. :)

darkagn 315 Veteran Poster Featured Poster

Rather than implementing the ActionListener in your class, it is probably better to add an ActionListener to your menu item. You can do this by

// Exit menu item
exitItem = new JMenuItem("Exit");
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,   ActionEvent.CTRL_MASK));
exitItem.addActionListener(new ActionListener() {
   public void actionEvent(Event e) {
      System.exit(0);
   }
});
fileMenu.add(exitItem);

However, if you need action listeners for every item in your GUI this code will create many classes, which may or may not be desired.

Another way of doing this would be to create your own actionListener class as an inner class and put the implentation in there, similar to your code which reads

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == exitItem)
{
System.exit(0);
}
}

but in another class. Then add that ActionListener to each of your items.

Hope this helps,
darkagn

darkagn 315 Veteran Poster Featured Poster

Yes I think your code will give you exactly one instance of your class.

darkagn 315 Veteran Poster Featured Poster

Hi there santhi1986 and welcome to Daniweb :)

We have a few rules here at Daniweb that you might want to read. Probably the most important one is that we can't do your homework for you, we need to see some effort before we try to guide you. What do you think is the answer to your problem?

An unwritten rule in this forum is that we don't revive old threads to ask our questions. We prefer it if you start your own thread to ask your question even if it is related.

Anyway let us know what you've done to solve the problem and we will try to help you out :)

Cheers
darkagn

darkagn 315 Veteran Poster Featured Poster

if (combi.equals(combi.toLowerCase()) || combi.equals(combi.toUpperCase()))

This statement in plain english reads:

if thisString equals thisStringConvertedToLowerCase or thisStringConvertedToUpperCase then...

This will ONLY be true if the entire string is written in lower or upper case. If there is any other combination of upper and lower case letters in your string it will return false.

I'm not 100% sure of what you are trying to do here...

darkagn 315 Veteran Poster Featured Poster

Just wondering, how does one's rep power increase? Is it to do with your own rep? Or the number of posts you have made? Or something else entirely?

darkagn 315 Veteran Poster Featured Poster

Hi there chaky1,

I would suggest downloading the latest drivers for your graphics card, but it might pay to post your question in one of the IT forums. This forum is specifically for game development and we don't necessarily know much about what might be happening with a particular game or graphics card.

Good luck,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi ronghel,

If I gave you a list of numbers and asked you which one was the biggest, how would you do that? (Not in code, just in life...)

For your second one, if I gave you a list of numbers and asked you if there were any duplicates in the list, how would you know?

For both just think about the steps you would take to solve each problem. Then worry about coding and testing after and it will be much easier :)

darkagn 315 Veteran Poster Featured Poster

Hello again,

I'm not sure about php (in fact I think you need to work in a server environment to write in php??) but for java the javac compiler is fine for a beginner. Also there are lots of really good tutorials and some great downloads and documentation on the sun website (sun are responsible for the development of the java language) http://java.sun.com/ . If you are planning on developing in the windows environment you might want to consider downloading Cygwin from their website http://www.cygwin.com/ which is a unix-style environment for windows.

Hope this gets you started,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hey there babyfrostie,

Are you having trouble reading the file, sorting the file or outputting the file? Because they are the three tasks you need to do...

darkagn 315 Veteran Poster Featured Poster

Hi there Joe and welcome to Daniweb,

IMHO there is no real right or wrong answer here. But speaking from personal experience I learned Java first then moved on to C and C++. I found this way of learning the three languages effective for me and there are a few reasons for this.

Java is called an object oriented language. Many people (myself included) find it easier to program in such a language because (almost) everything in the language is an object. This makes it easier to design and subsequently code.
Another reason why I found Java an easier first-up language was the compiler gives very descriptive errors when there is a problem with your code.

C++ is also object oriented in theory and is a very popular language. It is hard to see C++ becoming extinct because of this popularity. However I found that debugging C++ was particularly difficult for a beginner.

C is not object oriented at all, it is called a procedural language. I found C much harder to learn than the other two.

I don't really know much about C#.

However all of these languages do have a similar syntax to them. If you learn C++ chances are that you will at least be able to follow a java program and vice versa. In short, Java and/or C++ are both good languages to start with and my opinion stated above is probably a bit biased by the fact that …

darkagn 315 Veteran Poster Featured Poster

Could you write a small class that extends PdfContentByte and write a new method with the parameters that you want to pass that simply calls the original setCMYKColorFillF method followed by the showTextAligned method? Then you can call that new method as you need.

darkagn 315 Veteran Poster Featured Poster

I would convert letter to a char and then compare that char with your charArray word using

for (int i=0; i<array.size(); i++) {
  if (letter.charArray[0] == array[i]) {
    // the letter is at position i
  }
}
darkagn 315 Veteran Poster Featured Poster

Are you drawing in a JPanel (or JFrame) or an Applet? I think your problem might be as simple as calling repaint() after you do all your movement calculations?

darkagn 315 Veteran Poster Featured Poster

I'm getting hollystyles' and AD's problem but only in the Java forum and only sometimes. I'm browsing in firefox on xp also.

darkagn 315 Veteran Poster Featured Poster

No, those are local variables inside the method. They do not have access modifiers like "private".

Oops ... good point. :$

darkagn 315 Veteran Poster Featured Poster

So is that the code that moves your balloons? If not, what does? Sorry but I'm having a bit of trouble working out which part of your code does what...

darkagn 315 Veteran Poster Featured Poster

sara_84 has posted the code, but hasn't bothered yet to mention what are the problems regarding it.

Sorry about that Jishnu, sara_84 posted in two separate threads and a moderator has linked them. Now it looks like I asked her to post when she had already posted!

darkagn 315 Veteran Poster Featured Poster

Hi freddiecool and welcome to DaniWeb,

Not sure if this is your problem, but your variables should be initialised as private. ie:

private pryDialog pd = new pryDialog();
private int option = 0;
darkagn 315 Veteran Poster Featured Poster

All that method does is call itself though, I can't see when it will exit. This is called infinite recursion.

EDIT: Ah, my mistake, you are actually calling a slowMoveVertical(int) method in your slowMoveVertical() method. Can you post your code for the slowMoveVertical(int) method and I will try to help?

darkagn 315 Veteran Poster Featured Poster

Hi mir12 and welcome to DaniWeb,

We have pretty strict rules here about doing other people's homework for them (we won't!!) So you need to show us what you've done, and ask some specific questions about your problem.

darkagn 315 Veteran Poster Featured Poster

Is guessI the String or the JTextField in the GUI? If it is the text field then rajatC is correct :$

darkagn 315 Veteran Poster Featured Poster

if guessI is a String and word is a String then you can use the equals or equalsIgnoreCase methods to compare them.

if (guessI.equals(word)) {
// true if guessI and word are exactly the same
}
if (guessI.equalsIgnoreCase(word)) {
// true if they are the same regardless of case
}

There is no need to use a char array.

darkagn 315 Veteran Poster Featured Poster

Change line 102 to

PhoneInterface1 pi1 = new PhoneInterface1();
darkagn 315 Veteran Poster Featured Poster

your slowMoveVertical method seems like an infinite method to me. When does it stop?