7,116 Posted Topics
Re: What output do you get; [hello1[hello2]] ? A synchronised method like yours is synchronised on the current object (instance of the class). Because you have two different instances of B each invocation of sum is synchronised on a different object, so the synchronisation has no effect. If you synchronise them … | |
Re: Also remember you may be executing on a machine with multiple CPUs, each of which may support more than one simultaneous thread. So if you're on a top-of-the-range quad-core hyperthreaded desktop the answer is that your main thread and all three new threads could all execute at exactly the same … | |
Re: Yes. chars are numeric values that are interpreted as letters etc according to the Unicode system (same as ASCII for values <128). You can specify them either as a number or as a character in single quotes, or a mixture of the two. It's a fact that the letters a-z … | |
Re: Was that a question? You create row containing a Color.RED as its value and it's displayed as "java.awt.Color[r=255,g=0,b=0]", which is exactly what you would expect since the default renderer calls toString() on the value Object. To achieve the result you described in your first post I would expect to see … | |
Re: There's really only one way to do this right in Java, and that's to use a Listener, just like Swing does everywhere. Only snag is you have to implement it yourself, which is a bit tedious the first time (learning curve) but easy thereafter. You can use the existing ChangeListener … ![]() | |
Re: These other actions (eg "printing to screen") - 1. Are they a response to user input, or do they happen at various times independent of user interaction? 2. Are they "long running", eg taking more than 1 second to complete? If so, why? | |
Re: I don't know why I'm rewarding your laziness like this, but here's the code you could have / should have written for yourself in less time than it took to write that post [CODE] String input = "12/345/6789"; Scanner s = new Scanner(input).useDelimiter("/"); System.out.println(s.nextInt()); System.out.println(s.nextInt()); System.out.println(s.nextInt());[/CODE] | |
Re: Just ignore it. [CODE]Component content = MyWindow; panel.add(content, BorderLayout.WEST);[/CODE] I can't see any code to initialise MyWindow, so presumably its a null pointer, that gets copied to content, which leads to the NPE when you try to add it to your panel. | |
Re: Is there any way that you can explain that more clearly? I'm sorry but I have no idea what you are describing or asking. :( | |
Re: Have a look at the method that comes after [I]concat [/I]and before [I]contentEquals [/I]in the API doc for String. | |
Re: Integer.getInteger(tempNum) returns an Integer object, but your bsnk account constructor requires an int value. Have a look at Integer.parseInt(...) (Etc) | |
Re: Line 7 is that a "" or a " " ? When you get bugs like this try printing your working variables at key stages in the code, eg if you printed the contents of decryptArray, or even just decryptArray.length, that would confirm whether or not your split was working. | |
Re: Study the API documentation for DatagramSocket. It tells you exactly what parameters you can pass to the constructor (neither of yours has a valid parameter list). Judging by the parameters you tried to use, you are probably confusing DatagramSocket and DatagramPacket. | |
Re: Given the restriction of not using stuff you haven't been formally taught yet, I think you're doing very well. That's nice code, properly designed, formatted, commented etc. It looks quite professional. We see a lot worse code posted here. The sooner you can start working with more of the language … | |
Re: It's written in C (or one of its derivatives). This is the Java forum, so you're in the wrong place! | |
Re: For those of us who know nothing of basketball, perhaps you can explain what a 24 shot timer is and how it works. You may also find that the more precise your description is, the closer you will be to a software specification or design. ![]() | |
Re: Line 98 you use month to index an array, but you don't validate month until line 101. So an invalid month is going to throw an exception on line 98. You need to validate month first. Around line 92 you should print the exception e to see exactly what went … | |
Re: Yes, they are doubles, and nothing can change that. When you use df.format that takes your double value, formats it according to the specified format, and returns that value to you [B]as a String[/B]. So you need to declare a String variable to hold the formatted value. | |
Re: Starting with a Serializable object, you can write it to an ObjectOutputStream with a single write, and read it back from a corresponding ObjectInputStream ditto. NB: The JavaDoc for many classes warns that the serialisation format may change from one release of Java to another, so its not suitable for … | |
Re: This is exactly one of the most basic reasons for using any layout manager [I]except [/I]null. Any other layout manager will adjust your GUI to suit the resolution [B]and font sizes[/B] of each machine. But if you're on a tight deadline, and your teacher says don't worry about screen res, … | |
Re: Eclipse's [I]add unimplemented methods[/I] is a helper that kicks in when you declare a class that implements an interface or extends an abstract class but doesn't have all the necessary methods. The helper adds stub (empty) methods for all the missing methods. It's particularly useful when creating anonymous inner classes … | |
Re: I just read your equals method. What result would you expect from this? [CODE]Temperature t1 = new Temperature(32, 'F'); Temperature t2 = new Temperature(0, 'C'); System.out.println(t1.equals(t2));[/CODE] | |
Re: You can define or redefine the min and max values for the bar whenever you want. You can replace the % display when you update the value by calling setString, eg progressBar.setString(value + "/" + max); so I don't understand exactly what you want to do that is a problem. … | |
Re: A big advantage of setEnabled(false) is that the UI will automatically update the appearance of the buttons so it's clear to the user that they are disabled. | |
Re: You [arse using a default SimpleDateFormat - which is OK for printing, but far too detailed and complete to use as a parsing template for user date input. Better to create a SimpleDateFormat with a format that matches the current choice in your checkboxes. | |
Re: while(boolean stay=true) 1. This creates a new boolean when you should be using the one you already declared 2. = is assignment, == is the test for equals 3. (someBoolean == true) is a long version of (someBoolean) | |
Re: You don't say what layout manager you are using, but you could resize the components in the window depending on which menu item is selected, then pack() the window so it fits the re-sized components. | |
Re: If you have a [I]while (true)[/I] you may want to consider calling[B][I] break;[/I][/B] at some point to exit the loop. | |
Re: Yes, if you have a "non-static" object ("instance") you can use that to call non-static methods. This is true whether it's all happening inside a static or non-static method. | |
Re: Thank you for your contribution autorunman, but I'm quite sure from previous experience and from the actual post that Stultuske understood it perfectly well. His advice is excellent for someone who is looking at a larger project. Starting a larger project with "GUI classes with no program designs" may be … | |
Re: In general, if there is an aggregation relationship "an A has-many Bs" then you can use any member of the Collection hierarchy to hold multiple instances of B as an instance variable of A. A simple ArrayList<B> is the most obvious choice, but if you want to access those Bs … | |
Re: You create an action listener inside a method, and the code of the listener refers to one of the local variables in that method. The problem is that when the action listener is called, the original method will have finished executing, and its local variables will no longer be available. … | |
Re: At a guess that actionListener is attached to a JButton, yes? So e.getSource() returns the source of the action, which is your JButton You then try to cast it to a (JPasswordField), and that's illegal. You can't convert a button to a password field. What you need there is to … | |
Re: Just for clarity - because you may be misunderstanding what happens with the comma here: [CODE]private String[] ingredientName,units = new String [40];[/CODE] is equivalent to [CODE]private String[] ingredientName; private String[] units = new String [40];[/CODE] ![]() | |
Re: [CODE]private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { Vector v1=new Vector(); v1.add(jTextField1.getText()); v1.add(jTextField2.getText()); new tabel2(v1).setVisible(true);[/CODE] When you click the button you create a brand new tabel2 complete with its own brand new table model. The only data you pass it is a Vector with the latest values, so that's all it can display. … | |
Re: B's constructor doesn't have an explicit call to the superclass constructor, so the compiler inserts a default one, ie super(); But the superclass doesn't have a default constructor A() Either add a call the A's constructor in B's constructor, or add a default (no args) constructor to A | |
Re: You can convert both strings to the same case (eg toUpperCase() ) before checking if they are anagrams. ps line 58 if(value == true) is redundant. if(value) is quite sufficient. | |
Re: There's also a method to [I]split [/I]a String into an array of words. That could be useful - it's trivial to find the size of an array. | |
Re: x=0xffffff0; That's 7 hex digits, so the full value of your int, in hex is 0F FF FF F0 shifted 4 left that becomes FF FF FF 00 ints are stored as 1 sign bit (0 = positive, 1 = negative) and 31 bits of value. So on your 4th … | |
Re: It's hard to tell with you indentation in such a mess, but it looks like 33: double[][] earnings = new double[10][2]; is inside method jButton2ActionPerformed so the earnings array is created in that method, and disappears when the method ends. Each time you click the button you call the method … | |
Re: It will take you about 1 minute to write a tiny program to test this. Try it with xMethod declared static or not, and see what the result it. Tip: I have never known ~s.o.s~ to be wrong, never. | |
Re: It would if you did your own timer in a loop, but you can use a java.util.Timer to schedule a future call to your method, and that will use the system clock to wait until the right time. While it's waiting it uses zero resources, so it will have no … | |
Re: The source code for any Java program (desktop or applet) is visible only if the author chooses to make it visible. | |
Re: To do things like accessing files, handling the mouse events, or writing to the screen, the JVM has to deal with the operating system, not just the CPU hardware. ![]() | |
Re: Simple physics is not hard - store the objects current position and velocity. Use a timer to update them at regular intervals (eg 60 mSec). At each update change the position according to the velocity, and change the velocity according to gravity or friction. For gravity add a fixed downwards … | |
Re: Assuminbg this is a Java question, not JavaScript, use a JFormattedTextField [QUOTE]Formatted text fields provide a way for developers to specify the valid set of characters that can be typed in a text field. Specifically, the JFormattedTextField class adds a formatter and an object value to the features inherited from … | |
Re: IMHO you are using this facility in the wrong way. It's not there to explain API methods or to document them, it's just an aid for people who already know what they want. In other words it's a tool for experts, not beginners. You should always refer to the API … | |
![]() | Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in doing your homework for you. DaniWeb Member Rules include: "Do provide evidence of having done some work yourself if posting … |
Re: If you're using Windows then it's possibe to get this problem because Windows file names are not case-sensitive, but files within a jar are case-sensitive. So if the file name in you code differs in case from the real file name it will work in Windows, but not in a … | |
Re: You could use a text component, but if you don't expect the user to edit it in place, then a simple JLabel will work just fine. You display text in it by something as simple as myJLabel.setText(str); |
The End.