7,116 Posted Topics
Re: To store your shapes you need a suitable array - although for simplicity an ArrayList is easier. As each shape is created you can add it to the ArrayList, then you can loop thru the ArrayList calling draw() on each element - Java will see what kind of shape it … | |
Re: [QUOTE=Kishorey;858567]Is it possible to get the window size in Java [/QUOTE] the getSize() method, amazingly, will do it | |
Re: Java's not the best choice for this kind of thing. Here's a script that does what you want: [url]http://www.interclasse.com/scripts/killpopup.php[/url] | |
Re: Why use an array; that's just making your life harder than it needs to be. Use an ArrayList, which does everything an array does, plus you can just add your data to it with the add(...) method, and you never need to worry about it being big enough. | |
Re: The code for the button and its actionlistener are in the earlier post that shows all the code. I assume the later listing is just a subset. I must admit, I've spent quite a few minutes on this and can't see the fault... [edit] but a few minutes later... in … | |
Re: You need one more loop, to include your existing loops. This is the loop that will keep reading new sets until the file is empty. You can make it an infinite loop (while (true)...), and break or return out of it when the readline() hits E.O.F. | |
Re: Start by defining the class that extends LinkList and can store the data that needs storing for each event. Write its constructor(s) and any methods you need to access (get(...)) the data. Then move on to reading in values to pass to the constructor(s). Finally think about how to sort … | |
Re: I don't understand this question either. When you say "runs perfectly fine as long as ..." can you specify exactly what do you observe that is "wrong", and what it should be to be "right"? | |
Re: [QUOTE=BestJewSinceJC;847842] To know where the last item is, your program can either keep track of the size of the Vector, or you can use the Vector class's size() method. [/QUOTE] Definitely use size(), why do it yourself? | |
Re: [url]http://www.daniweb.com/forums/thread187065.html[/url] may be useful to you | |
Here's a question for those of you who have experience of fixing or enhancing other people's Java code, which I hope will also be really useful for those in the early stages of learning programming. Please contribute! If you've looked at other people's code, you will know that sinking feeling … | |
Re: Perhaps you should start by deciding what the array will look like, then write its declaration, then you can think about how to transfer data from the file to it. You also need to do the same for the data in the file, if you haven't already done so. | |
Re: Hi guys! Just saw this thread and had to join in! For me, the key issue about separation of GUI and model is about good architecture. Sure, you can hard-code calls to the GUI in the model, and hard-code calls to the model in the GUI, but if you do … | |
Re: [QUOTE=LevelSix;846725]So, a superscript? [URL="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/font/TextAttribute.html"]http://java.sun.com/j2se/1.4.2/docs/api/java/awt/font/TextAttribute.html[/URL] May be of use.[/QUOTE] Do they work in the console? I suspect not. You could use the unicode symbols for ² or ³ (00B2 and 00B3), but that's all, I think. In JLabels and the like you can use HTML formatting, of course. | |
Re: Woah guys. Couple of incorrect postings here: 1. If you don't declare a constructor as public, its scope will be limited to the package in which it's declared. This may, or may not. be what you intend. If you want to call it from another package it MUST be declared … | |
Re: I know this is marked as solved, but I think that's wrong - it's not solved, just ignored! By placing the "throws" clauses like that the program has specified that, if there is any problem locating a file, it will terminate immediately without any error message. That can't be a … | |
Re: As the user enters numbers add them to a List ( [url]http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html[/url] ). Then in a loop generate a random integer between 0 and the size() of the list. Get(int index) the element at that index, print it, then remove(int index) that element. Loop until the List is empty. | |
Re: Normally you would 3 setters and 3 getters. Is there any special reason why you want to do it that way? | |
Re: Is it possible that you have called the default constructor rather than the one with the port number, and thus connectToServer isn't executed, so the variables are not initialised when you call sendBytes? ps you declare the class as implementing Runnable, but I see no run() method??? | |
Re: System.out.println (short for Print Line) puts a newline char at the end whatever it prints, so you get one array element on each line. System.out.print does the same as System.out.println but does not add the newline, so that's the one you need. You'll then need to do your own newline … | |
Re: I'm not certain either, but if you mean use it like a desktop picture, try putting it in a JFrame and setting the JFrame with a combination of stuff like setUndecorated(true); setFocusableWindowState(false); toBack(); | |
Re: Re procedures - they are a sequence of steps that implement something useful. (As opposed to non-procedural languages such as HTML that describe the required results but do not give step-by-step instructions on how to achieve them). Java is procedural, and all procedures are implemented in methods (*). So one … | |
Re: Java's SimpleDateFormat class does exactly that - do you need to implement it yourself? | |
Re: You call a public static method from outside the class by using itsclass name and method name, eg XMLreader.readLatitude(...) | |
Re: In FTPServerReceiver you just have one input.read(), and it's not in a loop. Have you tried sending the buffer to System.out immediately after the read so you can see what's coming in? Where exactly is it failing? - try to scatter some System.out.println statements around so you can see how … | |
Re: Not certain that I understand the Q, but you can only have 1 run() in a class, so if there are other things you want to start new threads for you need an additional small Runnable class to do it. You can use an anonymous inner class (Google it if … | |
Re: IMHO design patterns are a great aid to good design. Why re-invent the wheel? Those patterns distil huge amounts of experience into templates that you can apply quite easily. However, I disagree that you "must" follow them, even less follow them blindly. You need to read, and understand them, then … | |
Re: I don't think there's a callback you can use, so the only way seems to be to set up a simple timer loop and call getMediaTime() at regular intervals, eg every 1 or 2 seconds, and then set the seek bar to the appropriate position. You should use the SwingTimer … | |
Re: Here's why: when you create a subclass, and you write a subclass constructor, and in that constructor you do not have a call to the superclass constructor as the first statement, the Java compiler puts in a call to super() by default (in order to ensure that everything inherited from … | |
Re: Maybe changing your class name to something other than vector will help avoid clashes with java's Vector class? | |
Re: You can get an aray of pixels to do your scanning/looking for algorithms by using the PixelGrabber class (I've attached some code I wrote earlier that will give you a head start). To decode an RGB pixel int, this works: [CODE=java]int pixel = // whatever, eg getPixel(x, y); // int … | |
Re: The first class tries to call a BagOfChips constructor with a parameter of type BagOfChips.Flavor, but you only have a constructor that takes a String. | |
Re: I just had a quick scan of your code, so I may have missed things, but... In the actionlistener you overwrite the value of sTable that you set up in the constructor, so it seems pointless to have passed the value into the constructor in the first place. Is this … | |
Re: Have a look at the Preferences class. It allows you to store & retrieve simple strings, ints, booleans etc in a very easy way, without having to bother about the details of where and how they are stored, basically: [CODE]Preferences prefs = Preferences.userRoot(); prefs.put(prefsItemName, prefsItemValue); ... prefs.get(prefsItemName, "");[/CODE] | |
Re: If you use ObjectOutputStream and ObjectInputStream you can send anything you want - Strings, complex Objects, whatever (as long as they are serialisable). | |
Re: No, it's not (unless there is other code in your app that needs to call a default constructor). | |
Re: [iCODE]java.awt.Desktop.getDesktop().browse(new URI("http://www.your.url")); [/iCODE] (needs Java .6) | |
Re: I have no idea why you want to do this! What's wrong with sorting a copy? Remember that the copy array, like the original, is simply an array of references (like pointers) to the Strings; you won't copy the actual Strings unless you go out of your way so to … | |
Re: The OO purist solution is to create a tiny class to hold info about the term of the polynomial., as in [CODE]class Term { private int power, multiplier; public Term(int power, multiplier) { etcv}; // getters as usual // other useful stuff such as calculating the term for a given … | |
Re: Why create a new stack in these methods. Just iterate thru the stack and add the elements? [CODE=java]int sum = 0; for (int i: stack) { sum += i; }[/CODE] | |
Re: The exception is thrown when the index is >= size, so it looks like there is nothing in Company_Cont_Mstr_ComboBox when this code is executed. (Maybe? happens when first cb is populated = fires change event, before 2nd is populated? Test size of Company_Cont_Mstr_ComboBox before setting its index in the change … | |
Re: Have you read this ? [url]http://code.google.com/p/nia-brew/[/url] | |
Re: toUpperCase in the Char class is a static method, so the correct way to use it is: charArray[i] = Char.toUpperCase(charArray[i]); You seem to be getting into difficulties with String vs char. It may be bettert to convert your String to a char array, do the selective case changes in the … | |
Re: It would be interesting to hear why you have rejected using paint() (or paintComponent()), because that's the "right" way to do it, and guarantees that you will handle things like windows being re-sized or covered/uncovered properly. Looking at your code as it stands, I expect that Swing will use paint() … | |
Re: Java only supports rectangular shapes for the parent window(ie the one that sits in the desktop). You can simulate other shapes by making part of the window transparent, leaving just (say) a circle visible. It's not that easy, but this reference will get you started... [url]http://www.pushing-pixels.org/?p=260[/url] | |
Re: The selection happens in the JTable, not in the underlying model, so you need to look at JTable methods like getSelectedRow() etc. | |
Re: com4j adds COM capabilities to Java in a simple way (well as simple as it';s going to get...). With it, you can use Excel's COM interface to do just about anything you want with a spreadsheet, from Java. It's free. See [url]https://com4j.dev.java.net/[/url] the download package includes a small Excel sample … | |
Re: this represents the object whose method is currently executing. A Thread is a separate stream of execution (eg if you have a dual processor, you can execute two threads simultaneously). Your class implements the Runnable interface, which consists simply of a public void run() method. So new Thread(this) creates a … |
The End.