Um, no. If you can't understand homework code that you have copied, that would be your own problem.
If you have a specific question about some operation that it is performing then post it.
Um, no. If you can't understand homework code that you have copied, that would be your own problem.
If you have a specific question about some operation that it is performing then post it.
There are two different ways you can approach drawing the spiral.
1) Using GeneralPath to define the path from a fixed coordinate system in which you define the coordinates of the segments to be drawn on a fixed x-y plane.
2) Using coordinate transformations (translate, rotate) to alter the coodinate system as you draw each segment. With translation and rotation, drawing the path becomes trivial. You simply draw a line in a fixed direction (which ever way you want to go from your origin, like 0,0 to 0,100, translate to the end of that line, rotate 90 deg left or right, draw a slightly shorter line in the same direction as the first (perhaps 0,0 to 0,90), and continue until you reach the endpoint you want. By moving and rotating your origin as you draw, you only have to draw increasingly shorter line segments in the direction of path traversal.
There are some examples of using coordinate transforms here:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/TransformTranslationandRotation.htm
Hope that helps get you started.
You need to re-examine the basic structure of your class. This will not compile. Your main() method is not declared correctly. Several methods and even the class itself has no end brace. At least go through and make sure the methods are properly structured before you worry about putting any code in them.
There isn't a specific function for that, but all you need to do is walk the tree and collect the parent references if node.isLeaf() is false.
lasher511's translation made as much sense. Hooray for irrelevant gibberish.
hi,
I have just give u the sample only and not the real circumstance where i used it.It does sounds good where i used it.Thanks,
Vivek
As jwenting said, public statics for anything but constants is usually a poor idea. There is probably a much better way for you to make that data available to your other classes.
You really don't want to realy on the users installing JMF to a particular place. It's much easier to manage if you just zip or tar your project into a structure that includes JMF in a /lib folder and use that with your class path. The zip or tar file is still portable, they just have to uncompress it wherever they like. Keeping third party libraries in the /lib folder makes it easier to manage for you and the users.
You won't be able to put jars in your jar. Typically you would just include that jar file in a" /lib" folder in your installation and add that reference to the class path entry in your application jar manifest file.
Labby, please remove the advertising from your post as well. It has no bearing on your question and is not approriate for the forum.
Edit: This probably doesn't apply now based upon the example code you posted while I was responding. You mentioned using those two hashtables in other classes without qualifying them by name, which is not what your example indicates.
Of course it will cause ambiguity. The only way to use them without the class name would be to use static imports and if both variables have the same name they cannot be resolved.
Even if you could, why on earth would you?
Also note, unless you have specific reasons for needing Hashtable (if don't know what those reasons are then you don't need it), you should consider using HashMap instead.
Quick addition on that code. Where the answer is compared, a null pointer exception is possible if no answer is chosen when you click ok. To fix it, change to this line
if (group.getSelection()!=null && group.getSelection().getActionCommand().equals(q.getCorrectAnswer())){
Also why are you so specific with the stuff u import? I am in the habbit of just ending them with .* cus it covers everything you need then and saves lines of code. is that bad practise?
If you are using many classes from a package, it can be just fine to use .* in most cases. If however one of your class names appears in multiple packages that you import with .*, like say List which is present in java.awt and java.util then it will be ambiguous and the compiler won't like it.
Visit here if you dare:
http://www.auschwitz.dk/Auschwitz.htm
I've stood in the middle of Dachau when the bells toll the hour. I'm perfectly aware of what some Germans did during those years of Hitler's reich.
It has absolutely no bearing on your posts. Others pointed out that what you attributed to Rove saying was essentially describing the "Big Lie" propaganda technique. Then you went off on some xenophobic tangent against Germans. Do you actually believe that all Germans support what was done in the Holocaust? I really hope that you don't, but even if you do it's completely irrelevant to what Dave posted. Perhaps you did not read the link past seeing the word "Hitler" near the top, but that is no one's fault but your own.
Well, you can't quite work with a custom input dialog like that. There is a way to do it with an Object array for responses, but if you want radio buttons you need to create your own custom dialog. Just for the heck of it, I wrote up one way you could put this all together with JDialogs. Of course, you could probably do it a bit easier with a simple panel. Perhaps this will give you some ideas to work from (the simple BoxLayout is pretty awful)
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.*;
public class QuizFourBib extends JDialog {
List<Question> questions = new ArrayList<Question>();
int score=0;
ButtonGroup group = new ButtonGroup();
JButton btnOk = new JButton("Ok");
public QuizFourBib(){
super();
setModal(true);
setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
questions.add(new Question("Who killed Goliath?", new String[]{"David", "Saul"}, "David"));
questions.add(new Question("Where was Moses born?", new String[]{"Egypt","Samaria"}, "Egypt"));
}
public int startQuiz(){
int score=0;
for (Question q : questions){
displayQuestion(q);
if (group.getSelection().getActionCommand().equals(q.getCorrectAnswer())){
score++;
}
}
dispose();
return score;
}
private void displayQuestion(Question q){
getContentPane().removeAll();
for (Enumeration buttonGroup=group.getElements(); buttonGroup.hasMoreElements(); ){
group.remove((AbstractButton)buttonGroup.nextElement());
}
JLabel questionText = new JLabel(q.getQuestion());
getContentPane().add(questionText);
for (String answer : q.getAnswers()){
JRadioButton radio = new JRadioButton(answer);
radio.setActionCommand(answer);
group.add(radio);
getContentPane().add(radio);
}
getContentPane().add(btnOk);
pack();
setVisible(true);
}
public static void main(String args[]) {
QuizFourBib quiz = new QuizFourBib();
int score = quiz.startQuiz();
JOptionPane.showMessageDialog(null,"Your score: "+score,"",JOptionPane.INFORMATION_MESSAGE);
}
class Question {
String question="";
String[] answers;
String correctAnswer;
public Question(String question, String[] possibleAnswers, String correctAnswer){
this.question …
Here you go with your insults again! You are a grown man Dave, come up with something of your own, and leave that Nazi stuff at home!
"Tell a lie often enough and it becomes the truth!" wasn't meant as advice, it was a warning by Carl what competitors might do.
I don't see where he is insulting you, unless pointing out the the words you ascribe to Rove have roots elsewhere counts as an insult.
Yes I do, the K is too German for my taste.
Too german? You have some issue with Germans that requires you to mispell names that appear Germanic?
I AM MOPPI
PC TECHNICIAN AND HERE TO SHARE SOME OF THE PROBLEMS I FACE IN THIS AS FAR AS LAPTOPS ARE CONCERN.i HAVE A COMPAQ ARMADA M700 LAPTOP WITH ME WHICH ONLY THE BATTERY, POWER KEEP ON BLINKING BUT NOT SWITCHING ALSO, THE NUMLOCK INDICATORS AND ARE ON AS WELL.
Obviosly caps lock is stuck on as well.
Try some of the things mentioned in this thread from JCreator forums:
http://www.jcreator.com/forums/lofiversion/index.php/t525.html
I think you just need to update the project properties.
Just compile and run it from the command line.
You don't show what code is getting that "s" object s.getStudentID()
but "s" is not getting cast to Student. It's still just Object, as indicated by the error message.
I've not used JECreator, but did you perhaps set a main class for your project somewhere? A properties window or some such? It sounds as if it still thinks that is your main class.
Err, which part "returns null".
By reading the documentation, maybe?
Yep, sounds like a good bet to me. They put that documentation in there for a reason :)
Read your Eclipse documentatioin for how to set the class path for libraries you are using in your project.
Read the error in its entirety, especially the name of the class it reports and the line number. Try to figure out why the compiler cannot see that class.
cannot find symbol when i included the xxxx.replaceSelection("replacement text");....??
Then "xxxx" is probably not a text component.
how can i save a file using a save button? heheh
I'm sure the site that I linked above has examples of using a BufferedWriter to write a text file as well. Writing to a file should have been covered in your class if you are expected to do that.
ok,thanks for giving the clue
can we copy a file from one directory to another directory using java?
Java does not have a native copy method. You must write your own short method for this using the IO classes. There are many implementations of copy available on the internet.
Can you elaborate a little more on the question? All object creation is done through constructors. If no constructor is specified, the compiler will supply a default empty constructor that basically does nothing. If you wish to provide info that initializes some values in the object when it's created, you provide a constructor for those parameters and initialize those values in that constructor.
Verify that you have the main class set. There is an an entry in the jar manifest.mf file Main-Class:
that specifies the main entry point class when the jar is run. If you have specified the main class in your project properties, this entry will be made automatically when you build the project.
Do we have any functions for retrieving the non-leaf nodes from the given tree?
Well, the children() collection and isLeaf() method give you the means to retrieve those, but I'm not aware of a specific method that returns only the non-leaf descendants.
Well, yeah it's ridiculous - if you wave your arms and point at only part of the story out of context.
When you include this part
Her next-door neighbour, a city police officer who was off-duty at the time, asked her to keep it down, police said. When she continued, the officer called police.
it's not so ridiculous.
She was screaming next to an open window. He asked her to be quiet. She did not, thereby essentially disturbing the peace.
Not really much of a foundation for melodramatic indignation.
How would I do that. I do not know how.. please let me know
http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html
Sure.
1) Learn the basics of the sort algorithm.
2) Learn the basics of a "double ended list" (doubly linked list you mean perhaps?).
3) Write code to perform the sort.
4) Post your code and questions if you encounter problems.
No, it's not correct. You need to re-examine the basics of class structure. You don't even have the class, constructor, and main method defined correctly.
This is just cobbled together pieces of UI creation code with no methods to actually do any computations. Even if it did compile it wouldn't do anything.
Your class path needs to include the location of DateComponent.
Are you compiling against JDK 1.5 or 1.6? Generics were introduced in 1.5 and if your JDK is older it won't like that declaration.
Well, you are probably right on the bloat. It all depends on how your menu items need to be used. If you have a single menu for the app, then just create a single menu bar class that manages those items. If you need to share those menu items among a few other classes, you may want to use a MenuItemFactory to centralize the creation of the items and get them as needed to compose other menus.
Creating small classes that implement Action is a good way to encapsulate what a menu item does and those actions can also be used with popup menus and buttons.
It's really a matter of balancing your usage needs with the bloat that can occur by making every tiny thing a separate class. There isn't so much one "right" answer as there is a good flexible solution for your particular context... and that is where the "art" part of software development comes in.
The modification is occurring because you are adding all of the child nodes of the selected node to a new root. The add(MutableTreeNode) method states that it disconnects the added node from its parent and makes it a child of the node it's added to. I see that you tried to use clone() on the selected node, but that fails because they implemented clone() as a shallow copy operation. It does not copy the parent nor children references (deep copy).
How to fix it depends on what you intend to do with the "prime" subtree. If you do not need to modify it without changing the original tree and you can do without the new root node "ResultTree", then the changes I put in bold in the code below will work for you.
If you absolutely need a separate copy of that structure, then you will have to write your own deep copy method that clones a node recursively by cloning that node and its children and all subsequent children of those children. That's not really hard to do, but if you don't need the separate copy you don't need to bother with it.
Sorry......the code given above could not display properly. So I am resending the code back in proper form.
import java.awt.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import java.util.Iterator; import java.util.List; import org.jdom.*; import org.jdom.input.SAXBuilder; import java.io.File; import java.awt.event.*; public class XMLTreeViewer extends JFrame implements ActionListener{ //The JTree to display the XML private JTree xmlTree; …
Hi,
Thanks for the reply. But by doing the above I will be able to modify the original tree that I have and will not be able to display the original tree that I have.
How can I display the subtree in another window or frame such that my original tree is preserved??
Please help me out in this.....
Thanks!!!
Just create a new JTree component and use the code above to create it's model. In my example, I replaced the existing model the new one. You can just as easily keep the original and work with multiple JTrees.
My dad says, that if you have too many credit cards, it can count as a liability against you when you apply for a loan.
This is true. If your total available credit, which is the total of all credit lines available to you, exceeds a certain percentage of your income, it can lower your credit score. That must be weighed when considering whether to keep or cancel old cards or if you are considering a new card.
Even if you have no balance on any line of credit at the time, if that credit is available to you it is a factor in your score. For all they know, you could max all those cards tomorrow and go from zero debt to total available credit in debt.
I currently have 2 credit cards, one of which I make nearly all my purchases on (though it's always backed up from my checking account so I'm never in debt), and one which I never use and should cancel. I'm looking to maybe get a different one though...
If you only have the two cards and have a good credit history on both of them, you may want to keep the unused card for the benefit of your credit score. This article discusses the details: http://www.fool.com/investing/small-cap/2004/08/30/beware-of-canceling-credit-cards.aspx
Well, if you don't start your while loop within a comment, it will probably exit as you expect.
boolean stop = false; //controls if loop below executed [B]while (!stop)[/B]
{
No, because the button has no concept of what it is next to. That depends on where you put them, so you have to code your own method to determine what "next to" should be. Of course, the component does know things like it's local coordinates, which could certainly be used to figure it out.
plz help me how can we find out the size of a file or a directory using IO package in java?
I've already told you: File has all of the methods you need. The length() method returns the length of the file in bytes. If the file is a directory, you will need to recursively sum up the length of the files in the that directory, which is obtained with the list() method.
If you had taken the time to look at the APIs that I suggested this should have been fairly straightforward.
I'm still not exactly clear on the behavior you are wanting. You wish to replace the displayed tree with the selected subtree? Or you want to present that subtree in another location separate from the main document tree?
If you want to replace the existing displayed tree with a selected subtree, you can change your selection listenter to do this
//add Listener to Print to Screen the xml tag selected
xmlTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent evt) {
// Get all nodes whose selection status has changed
TreePath[] paths = evt.getPaths();
// Print the last Path Component selected
System.out.println(evt.getPath().getLastPathComponent());
[B] DefaultTreeModel newModel = new DefaultTreeModel((TreeNode)evt.getPath().getLastPathComponent());
xmlTree.setModel(newModel);[/B]
//print the full path from the selected tag
// System.out.println(evt.getPath().toString());
}
});
That of course discards the overall document model unless you retain that as a separate reference, which you would need if you wanted any way to go back after navigation.
I'm not sure if that is what you are wanting, but maybe it gets you close. If it totally misses what you are wanting to do, post a little more detail on what you wish to do with the selected subtree.
I'm not clear on what you want to do with the subtrees when you say "get the subtrees". If you select a node, you essentially have that subtree via it's children collection. What you do with that collection depends on your needs, so perhaps a bit more info would help.
Well, as the message says File not found: Computer.java
. Make sure that the file is actually in that directory and you have not misspelled the name.
This search might yield a good starting point.
http://www.google.com/search?q=simple+%22name+disambiguation%22+&btnG=Search&hl=en
As you might imagine, it can get fairly deep pretty quickly depending upon your expectations.
The compiler gives you more information than just "errors".
Post the errors and what you think might be the reason for them. You need to learn how to interpret those messages and deal with the cause. Throwing up your hands and saying "I have errors!" won't get you too far.
It's going to be hard to set those name and value properties if you don't ever declare them.