7,116 Posted Topics

Member Avatar for LianaN

1. Create a new class that contains a label and a textfield and write the necessary constructor(s) and other methods. 2. If you just want it for positioning etc, put them both in a JPanel

Member Avatar for LianaN
0
119
Member Avatar for musikluver4

That whole block of code simply tells Java to exit the app when the window is closed, so just remove it or each window that should not call System.exit when it is closed.

Member Avatar for JamesCherrill
0
129
Member Avatar for LianaN

5 seconds or 5 minutes? Are you doing those long-running tasks on the Swing event thread? If so, move them to a SwingWorker thread so they execute in the background while the GUI continues to display

Member Avatar for Ezzaral
0
451
Member Avatar for shane1987

Your pseudo-code looks OK. Now, back to the test driver. You have all your code in main, which makes this difficult - so the first thing is to move the number generator into a new method that returns an array of 50 different random numbers, eg [CODE]public int[] generateNumbers() { …

Member Avatar for shane1987
-1
155
Member Avatar for krip_101

passnum[i] = 26;} int table[][] = new int [26][26]; table[passnum[i]][passnum[i++]]++ Now can you see it? (the max valid index for an array[26] is 25)

Member Avatar for JamesCherrill
0
103
Member Avatar for jon.kiparsky

I really want to endorse the "println" approach. Some of the hardest problems to solve are because: 1. You have an incorrect understanding of how some API works, or 2. You are missing something that you didn't know you needed In both cases no amount of introspection or code re-reading …

Member Avatar for apines
1
127
Member Avatar for yap_1991

The SwingWorker class is designed for running long-running tasks in the background with a Swing GUI.

Member Avatar for JamesCherrill
0
209
Member Avatar for enfamos

When you split the code into classes you ended up with "import" statements in the middle of your file. That's illegal, they must be the first thing in the file (except for a "package" statement). So either you just put the imports at the beginning and leave all your classes …

Member Avatar for enfamos
0
168
Member Avatar for TahoeSands

There shouldn't be any problem doing this with a JLabel. You can set the size, fg/bg colours (including transparent background), font, style and point size etc. You can position it wherever you like by using a null LayoutManager. It will automatically display on top of the JFrame. You may have …

Member Avatar for Ezzaral
0
82
Member Avatar for Sunshineserene

Sunshineserene: you are making this very difficult for anyone to help you because your problem description is so vague. Exactly which array in exactly which class is being "called" from exactly where? Please specify the exact line numbers where the variables and code in question can be found.

Member Avatar for Sunshineserene
0
2K
Member Avatar for bibiki

You have overidden paint(Graphics g) but this is not a recommended practice. paint(Graphics g) also has responsibility for painting child objects etc, and this can all get lost when you override it. The recommended practice is to override paintComponent(Graphics g) instead. You override it in exactly the same way, but …

Member Avatar for kramerd
0
202
Member Avatar for ceyesuma

In a word - yes. You need to call JFileChoser in response to some kind of user interaction - eg clicking a menu item. The JFileChooser returns you a File object, so you then open some kind of output Stream (eg new ObjectOutputStream) to that File, and write your data …

Member Avatar for JamesCherrill
0
108
Member Avatar for blknmld69

main line 44 You create the pw using the no-args constructor which you document as follows: [QUOTE]The no-arg constructor initializes an object with null* strings for name, employee number, and hire date.[/QUOTE] You then immediately print it put and get empty data - just like you said! Nowhere do you …

Member Avatar for Overbooked
0
8K
Member Avatar for LianaN

Your setValue looks OK as far as it goes, but there's no way for the JList to know that you've done that, so it doesn't update itself. After changing your model's data you must call fireContentsChanged (inherited from AbstractListModel) to notify listeners (including the JList) that something has changed - …

Member Avatar for JamesCherrill
0
2K
Member Avatar for StaticX

Separation of user interface and logic/model is a fundamental design pattern that is followed by all serious code. Here's a simple heuristic for determining where to put any particular function: Ask yourself "suppose I write two versions, one with a GUI, one with a command-line interface (or maybe an HTML …

Member Avatar for StaticX
0
159
Member Avatar for hatux

2d arrays in Java are just an array of arrays. You have arrays of words, so you can just add those to an array of sentences - roughly like this... [CODE] String[][] data = new String[99][]; // first dim big enough for all sentences int sentenceNum = 0; while (lineScanner.hasNext()){ …

Member Avatar for JamesCherrill
0
102
Member Avatar for neo_31591

Put all the code to run the SELECT and update the gui into a single small new method, with the v1 value as a parameter... [CODE]public void displayQuestion(int questionID) { Statement s = con.createStatement(); s.execute("SELECT Question FROM Ques WHERE ID=" + questionID); // update GUI etc }[/CODE] then in your …

Member Avatar for JamesCherrill
0
79
Member Avatar for Dhruv Gairola

AffineTransform. You create an instance of AffineTransform that maps the rotation you want and apply that to a Graphics2D instance with setTransform(...). Paint your icon to the Graphics2D and hey-presto, you have a rotated icon. Here's a quick intro: [url]http://www.javareference.com/jrexamples/viewexample.jsp?id=88[/url]

Member Avatar for Dhruv Gairola
0
80
Member Avatar for supertux

Looking at the code you posted I can't see anything that initialises connectionFactory, so I'm unsurprised that connectionFactory.createConnection() gives an NPE.

Member Avatar for JamesCherrill
0
174
Member Avatar for Son of a gun

Your public variable is an instance variable, so you need an instance of StringArrays to access it OR you can make it static and access it via the class name, ie [CODE]// instance version - how to reference StringArrays sa = new StringArrays(); ... sa.Anglia; // static version - how …

Member Avatar for Son of a gun
0
111
Member Avatar for 123a

If you need to create a variable number of ArrayLists then you will need some kind of container to put them in, eg an array or ArrayLists or an ArrayList of ArrayLists. Start with an new empty container, then in your loop create copies of the original ArrayList and add …

Member Avatar for JamesCherrill
0
124
Member Avatar for Khodz

For simple cases like this you can just declare some kind of collection (eg ArrayList) as a static variable in the class, then, in the constructor, add the new instance to the collection.

Member Avatar for Khodz
0
629
Member Avatar for o0oKodako0o

This is the expected behaviour. What exactly is the problem you are trying to solve?

Member Avatar for o0oKodako0o
0
657
Member Avatar for muncher10

You don't initialise Smallest, so it starts as 0, so if all your values are >0, smallest will always be zero. Best to initialise it to the largest valid int value. double avg; avg = sum / count; Although you have declared avg as double, the calc of sum/count is …

Member Avatar for apines
0
157
Member Avatar for Buffalo101

You set the model for tabel in the init method (line 75), but then after returning from that you set a different model for tabel (line 39). That seems odd.

Member Avatar for Buffalo101
0
440
Member Avatar for hwalsh

You declare (at least) three different variables called userName. This is almost certainly a mistake. Just keep the very first one, and in the other 2 places just use the first one, eg instead of [CODE]String userName = reader.nextLine(); // creates a new userName local to this method[/CODE] just have …

Member Avatar for hwalsh
0
88
Member Avatar for kezkez

pseudocode: [CODE]define class for new objects 3 variables constructor that takes 3 values to set the variables ... actionperformed loop: read next line from file use split (as above) to separate the 3 fields create new object using the 3 fields add new object to an ArrayList end loop[/CODE]

Member Avatar for JamesCherrill
0
155
Member Avatar for seekdestroy

How about looping thru the top cards (no need for the ArrayList) and building a HashTable<Card, Integer> showing the number of occurrences of each card, ie for each top card: if hashtable's keys contain this card, increment its counter else add a new entry (card, 1) Then you know exactly …

Member Avatar for apines
0
13K
Member Avatar for Awesomeness
Member Avatar for mangopearapples
Re: Mp3

Java Media Framework (JMF) - although it's not as good as it shoul dbe.

Member Avatar for mangopearapples
0
172
Member Avatar for someone5
Re: help

You can add a ListSelectionListener to the first list. It will be called whenever the user changes his selection in the list. When that is called you can query which line is selected and use that to put the appropriate data in the second list.

Member Avatar for someone5
0
206
Member Avatar for debasishgang7

Count and match your quotes - there are 7 on that line = 1 unmatched. The colour coding (blue = string literal) in your posted code is a good clue.

Member Avatar for JamesCherrill
0
176
Member Avatar for o0oKodako0o

Java assumes that a class is not Serializsable (ie not able to be written to an Object stream) unless you explicitly say it is. To do that you declare the class as implements Serializable (check out the API for the Serializable interface) If all your class data is just regular …

Member Avatar for Buffalo101
0
172
Member Avatar for jems5

y > x > 1 [I]y > x[/I] returns a boolean (true/false), so then it continues [I]boolean > 1[/I] which is invalid - you can't compare a boolean and an int. You need to compare y with x, then compare x with 0, then "and" the two results together ie …

Member Avatar for JamesCherrill
0
146
Member Avatar for purijatin

Does [2] run in its own thread? Presumably it needs to wait until there something in the list? If so, the normal solution is to use a LinkedBlockingQueue - you will find the documentation in the usual places.

Member Avatar for JamesCherrill
0
93
Member Avatar for scripter_tmrage

There are a couple of ways to play a simple sound in Java. This explains the newer. better (but harder) way: [url]http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml[/url] and this is the older, simpler,way: [url]http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java[/url] Either way, you call the appropriate code from your actionPerformed method.

Member Avatar for scripter_tmrage
0
143
Member Avatar for PDB1982

Are you wanting to add the two arrays as two elements, or are you wanting to add all the elements in the arrays? For the first case [CODE] int[] a = {1,2,3}; int[] b = {4,5}; HashSet h = new HashSet(); h.add(a); h.add(b); for (Object o : h) System.out.println(o); // …

Member Avatar for JamesCherrill
0
97
Member Avatar for Andy_Parr

You can catapult this to a higher level by creating a class for the stores and their coordinates - something like: [CODE]class Store { String name; int x, y, width, height; int doorX. (etc)[/CODE] Pass all the coords to the constructor. Then have methods in the class like [CODE]public void …

Member Avatar for JamesCherrill
0
638
Member Avatar for gedas

Open the file writer in append mode : new FileWriter("file4.txt", true)

Member Avatar for gedas
0
88
Member Avatar for khaled_jawaher
Member Avatar for powerson65
Member Avatar for richies

Is this for homework? What's [B][I]your [/I][/B]theory as to why this code will not work (apart from spelling errots!)

Member Avatar for stultuske
0
120
Member Avatar for Robban

[CODE]// pseudo code int max (int [] v) { if (v has only 1 element) return that element int[] v1 = copy of v excluding the first element int maxV1= max(v1) if (first element of v > maxV1) return first element of v; return maxV1; }[/CODE]

Member Avatar for JamesCherrill
0
189
Member Avatar for juniper2009

You have created an action listener, but you have not associated it with the button. Check out the addActionListener method that JButton inherits from its supercalss AbstractButton

Member Avatar for JamesCherrill
0
114
Member Avatar for dreamslct

I haven't tried this myself but... The message String is displayed in a JLabel, so you should be able to use simple HTML to format the text. eg "<HTML><H1>This is a message</H1></HTML>"

Member Avatar for JamesCherrill
0
202
Member Avatar for jdiddy
Member Avatar for oceanside013

Your toString looks fine. You could add more of the data items if you want. The equals method seems valid - but not what I would expect. It seems to say that two scores are "equal" if one of them has the same data as the other's "friend" data. Normally …

Member Avatar for JamesCherrill
0
165
Member Avatar for ceyesuma
Member Avatar for ceyesuma
0
156
Member Avatar for Spiderpig085

It's a problem with the package names - you seem to have the class name at the end of the package names, which is syntactically valid, but not a normal thing to do. I would start by putting them both in the same package package myJava.SimpleFrame; and there's no need …

Member Avatar for Spiderpig085
0
208
Member Avatar for Sunshineserene

This discussion about the array size seems to have gone off in a strange direction. Regardless of where you get the array from you can find out its length at runtime using the "length" attribute that every array has. The following code illustrates this [CODE]for (int i = 0; i …

Member Avatar for JamesCherrill
0
160

The End.