7,116 Posted Topics
Re: You need to pass the paintComponent's graphics object to the highlight method and paint onto that. Because of double-buffering and other hidden Swing internals the this.getGraphics() graphics object is is no real use to you. | |
Re: You have 4 connections throiugh one *ServerSocket*, but only one per *Socket* - the difference is important. It's always a bit messy clsing a Socket connection when you have input/output streams going in both directions. Whichever end closes first will trigger a SocketException at the other end. ALl you can … | |
Re: The align specs apply to a whole paragraph, so you can't mix them on one line. You could try ALIGN_JUSTIFIED. | |
Re: The only thing that looks odd to me is Client line 21 out.flush(); where you flush before the first write. That's probably harmless, but definitely redundant, so maybe try taking it out? | |
Re: I don't understand why you are getting into Java reflection to use this jar. Reflection would count as as "advanced" topic, asnd most programs will never use it. You should be able just to call a TextEditor constructor without using reflection. There';s an example of that in the source code, … | |
Re: You can download the source code, which also has no doc, but there's a simple main method that looks like a kind of demo of how to use it. Personally I wouldn't touch undocumented code with a 10 meter pole. | |
Re: Somewhere you should have a method that executes at regular intervals (eg 30 per second) to update the position according to the velocity. (A javax.swing.Timer is the best way to do that.) That's where you need to have your velocity_Y -= gravity; y += velocity_Y; //set y | |
Re: To compare two Objects you can either: 1. Implement the *Comparable* interface (which consists of a *compareTo* method) in the objects being compared, or 2. Write a *Comparator* that compares two arbitrary Objects Both these interfaces are documented in the usual Java API documentation. In this case it would be … | |
Re: [QUOTE]JList() Constructs a JList with an empty, read-only, model.[/QUOTE] The API says it all. | |
Re: Wow! What evil genius created that example? I suspect the answer will be clearer if you have a large cup of strong coffee then work through what that code looks like after after type erasure, considering different parameters that could be passed to doStuff at runtime (whose exact details may … | |
Re: > why should i implement a new subtree that all are empty? So you can add Objects to it later | |
Re: DaniWeb Member Rules include: "Do not hijack old threads by posting a new question as a reply to an old one" http://www.daniweb.com/community/rules Please start your own new thread for your question This thread is closed. | |
Re: 4th bullet point - that's not a new JComboBox, it's just a new reference to an existing JComboBox. | |
Re: Your java compiler would have answered that faster than anyone at DaniWeb could have done! | |
Re: if class A is in package xcom, javac will look for A.java inside a folder (or jar) called xcom, starting from the classpath. If the classpath includes the xcom directory javac will look in xcom for a folder (or jar) called xcom and, of course, it won't find one there. | |
Re: > what is in ready method? It is documented in the API doc for it class (FileReader), just like every other API method. Bulldogs: Please always post the complete text of the error messages you get from the compiler or the Java runtime. They usually tell you exactly what is … | |
Re: Yes, of course you can get help here, but please remember DaniWeb Member Rules (which you agreed to when you signed up), including: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone … | |
Re: Something like that should work. The problem must lie somewhere else. Maybe if you post the actual code that isn't working...? | |
Re: The are more Google hits for "BCD" than you can imagine. Which meaning of "BCD" are you interested in? | |
Re: Schol-R-LEA gave you the answer. GregorianCalendar. Look it up in the API doc. | |
Re: In the Cup class, why not have two instance variables for the Closet and Shelf, and update these when the Cup is moved? In the User class you just need a List of each user's Cups | |
Re: Java Swing painting doesn't work like that, no matter how reasonable that looks. Swing is in charge of app drawing, and has all kinds of hidden double-buffering etc behind the scenes. If you simply update that Graphics "behind Swing's back" there's no guarantee about when or even whether that will … | |
Re: Can't be bothered to mess around with your zip - please post code in proper format here. But at a guess you're blocking the Swing thread... Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event Dispatch Thread", or "EDT", … | |
Re: @piyush Please don't just spoon feed raw code to people. All that teaches them is how easy it is to cheat with a quick copy/paste. You didn't even attempt to explain why you made the changes you did. Give people assistance that helps them learn how to fix problems for … | |
Re: Details depend on what you are removing from (ArrayList, HashSet etc?), but re-starting the find from the beginning each time is what gives you the O(N^2). Use an algorithm that just searches once through the data, removing as it goes. (You may need to start at the end of the … | |
Re: What's the rest of your classpath? It should be a ilst of all the directories where Java needs to look to find packages/classes | |
Re: Problem's on line 15. Obviously misunderstood what valueOf does. You need to use either substring or charAt there to pick out each char of the user's input string, then you can use parseInt to convert that one character to a number. There are better ways to handle each single character, … | |
Re: You use getData().getDataElements(... which can return all kinds of different formats, depending on the image source. Your apparent assumption that it's 3 bytes/pixel may be wrong? (Most commonly you see one 32-bit int per pixel containing ARGB values that you can unpack with shift/mask operation). Have a look at the … | |
Re: Google *Factory Design pattern* The very first link takes you to the Wikipedia entry that answers your question. In future please try to do at least a little research before asking someone to spend their valuable time helping you. | |
Re: Maybe create some kind of `Map<String, ArrayList<String>>` where the keys are the unique different last part of the words and the values are lists of all the words that end with that last part. That's a relatively esasy structure to build as you iterate through the sorce data, and at … | |
Re: int numbValues; // not initialised, will be zero int[] values = new int[numbValues]; // array of zero elements, any index will be out of bounds Object(int numbValues) { this.numbValues = numbValues; // updates numValues, but too late to affect size of array } . | |
Re: The message is perfectly clear - you defined a Player class and it doesn't have a getDocumentBase method. That method is defined in the Applet class. Main extends Applet, so you can call the method there and maybe pass the result to PLayer's constructor, or maybe proving a tiny get … | |
Re: public Image getPlayerImage() { return mario.getImage(); } mario already is an Image, so you just need to return it "as-is" public Image getPlayerImage() { return mario; } When you initialise mario you have specified both a document base, and a fully-qualified path/file starting at c: YOu should have one ofr … | |
Re: Right now you don't have enough specification to begin thinking about design, even less code. Start with a specification. Think of a few typical games that you would want to implement with the engine. For each game write down what functionality should be in the engine, and what should be … | |
Re: That's OK. Taywin's code is to check that you are getting the String from the text field correctly. Now we know that's OK we can move on. Taywin has also posted a lot of code that shows how you should approach the parsing. What part of that is causing you … | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: DaniWeb Member Rules include: "Do not hijack old threads by posting a new question as a reply to an old one" http://www.daniweb.com/community/rules Please start your own new thread for your question This thread is closed. | |
Re: Rather than read the number fron the console as an int, you could read it as a String, then use the charAt method to access each char in turn in a simple loop. You can compare each char with the previous largest char to find the overall largest (that part … | |
Re: > I didn't realise that Java would give public modifier to the constructor by default if there is none You were right not top realise that, because it's not true! Java Language Specification section 8.8.4: > If no access modifier is specified for the constructor of a normal class, the … | |
Re: This isn't a "we do your homework" service! Try to answer it yourself. Post your best answer here. Based on that people will give you the help you need. DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself … | |
Re: I don't think anyone has seriously used this technique since double-buffereing (etc) was introduced aroubd Java 1.5 (?). Simply create a subclass of JPanel. Load your image into memory in the constructor. Override its paintComponent to paint your image onto the Graphics passed as parameter. | |
Re: @subramanya.vl babi.meloo is obviously a beginner. Do you seriously think that they will understand how "\\\\s+" works? All they could do is copy/paste it like some Harry Potter spell and hope it works. Teach, explain. | |
Re: You have a choice of strategies, including: Old-fashioned programming: In your loop look at two chars (eg charAt(i) and charAt(i-1)) so you can detect all cases where a blank is followed by a non-blank (ie the start of a word). You'll have the special-case the very first char in the … | |
Re: Nor sure exactly what you are asking here... is this about writing your Java program, or how to configure Windows shell to add items to the right-click explorer context menu? For the Java side - you can accept the file name into your program as a string parameter on your … | |
Re: "memory problems" in Java are pretty much limited to Java throwing an out of memory exception. If you don't have such an exception it's 99% certain you have a problem with your code. | |
Re: Are you catching any exceptions and printing the stack trace? | |
Re: Use the number the user types in in a ***switch*** statement to call the appropriate method. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html | |
Re: Your Generic class definition says that the type T of the array must extend/implement Comparable. int isn't an Object, and doesn't implement anything, so your class cannot work with an int array. In fact all generic types must be Objects, never primitives, so there's nothing you can do to make … | |
Re: What EXACTLY happens when you try to type in which text field? | |
Re: window is a variable. From the context I guess its a top-level Swing component (JFrame, JDialog, JApplet...) getSize() is a method that's available for all Swing components. Top-level components inherit it from java.awt.Component. Others inherit it from javax.swing.JComponent. ps *window.setLocationRelativeTo(null); * does the same thing as that code, but in … |
The End.