7,116 Posted Topics

Member Avatar for gourav1

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 …

Member Avatar for zeroliken
0
163
Member Avatar for gourav1

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 …

Member Avatar for ~s.o.s~
0
329
Member Avatar for rotten69

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 …

Member Avatar for rotten69
0
186
Member Avatar for nsyncpilu

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 …

Member Avatar for nsyncpilu
0
1K
Member Avatar for n3red

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 …

Member Avatar for hfx642
0
1K
Member Avatar for deanus

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?

Member Avatar for JamesCherrill
0
86
Member Avatar for dark_sider_1

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]

Member Avatar for JamesCherrill
0
216
Member Avatar for infinitus

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.

Member Avatar for infinitus
0
256
Member Avatar for singhs18

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. :(

Member Avatar for singhs18
0
178
Member Avatar for mrjeck2008

Have a look at the method that comes after [I]concat [/I]and before [I]contentEquals [/I]in the API doc for String.

Member Avatar for NormR1
0
584
Member Avatar for Nandomo

Integer.getInteger(tempNum) returns an Integer object, but your bsnk account constructor requires an int value. Have a look at Integer.parseInt(...) (Etc)

Member Avatar for JamesCherrill
0
143
Member Avatar for Ntropy

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.

Member Avatar for Ntropy
0
216
Member Avatar for dmtYork921

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.

Member Avatar for JamesCherrill
0
189
Member Avatar for Morney

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 …

Member Avatar for Morney
0
749
Member Avatar for venkat4krish

It's written in C (or one of its derivatives). This is the Java forum, so you're in the wrong place!

Member Avatar for zeroliken
0
235
Member Avatar for twinkle2011

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.

Member Avatar for hfx642
0
540
Member Avatar for Ntropy

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 …

Member Avatar for JamesCherrill
0
239
Member Avatar for jaxi

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.

Member Avatar for jaxi
0
350
Member Avatar for riahc3

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 …

Member Avatar for riahc3
0
939
Member Avatar for vaironl

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, …

Member Avatar for vaironl
0
146
Member Avatar for pankajagar2002

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 …

Member Avatar for pankajagar2002
0
1K
Member Avatar for dsoto

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]

Member Avatar for NormR1
0
1K
Member Avatar for n3red

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. …

Member Avatar for JamesCherrill
0
102
Member Avatar for twinkle2011

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.

Member Avatar for JamesCherrill
0
383
Member Avatar for sandman64

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.

Member Avatar for sandman64
0
194
Member Avatar for SketchGamer

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)

Member Avatar for zeroliken
0
1K
Member Avatar for skylinepkr

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.

Member Avatar for skylinepkr
0
125
Member Avatar for Daigan

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.

Member Avatar for Daigan
0
170
Member Avatar for gourav1

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.

Member Avatar for gourav1
0
106
Member Avatar for n3red

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 …

Member Avatar for JamesCherrill
0
236
Member Avatar for creative_m

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 …

Member Avatar for JamesCherrill
0
192
Member Avatar for bRyANthen

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. …

Member Avatar for JamesCherrill
0
198
Member Avatar for ethio

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 …

Member Avatar for stultuske
0
832
Member Avatar for vaironl

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]

Member Avatar for hfx642
0
146
Member Avatar for inamul20

[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. …

Member Avatar for JamesCherrill
0
236
Member Avatar for arias36028

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

Member Avatar for JamesCherrill
0
273
Member Avatar for stevemag

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.

Member Avatar for stultuske
0
316
Member Avatar for Ambitious girl

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.

Member Avatar for NormR1
0
105
Member Avatar for gourav1

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 …

Member Avatar for JamesCherrill
0
311
Member Avatar for JaffaApophis

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 …

Member Avatar for JamesCherrill
0
452
Member Avatar for divsok

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.

Member Avatar for stultuske
0
1K
Member Avatar for glenak

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 …

Member Avatar for NormR1
0
104
Member Avatar for Panathinaikos22

The source code for any Java program (desktop or applet) is visible only if the author chooses to make it visible.

Member Avatar for jwenting
0
268
Member Avatar for dineshswamy

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.

Member Avatar for hfx642
0
105
Member Avatar for sirlink99

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 …

Member Avatar for sirlink99
0
87
Member Avatar for tqmd1

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 …

Member Avatar for JamesCherrill
0
141
Member Avatar for Panathinaikos22

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 …

Member Avatar for Panathinaikos22
0
100
Member Avatar for maawali

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 …

Member Avatar for JamesCherrill
-1
64
Member Avatar for Joey_Brown

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 …

Member Avatar for NormR1
0
174
Member Avatar for spades0001

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);

Member Avatar for JamesCherrill
0
175

The End.