|
|
I have a question,please help me,how can i distinguish and declare 1 method and 1 object in java?
Example:static void main(String[]args)throws Exception{
public static Test(int a){
}
}
Why i have to declare(int a)?
I am a newbie and please help me.
|
|
|
|
|
Why are you trying to declare one method (Test) inside of another method (main)? I don't think Java supports that...
As for "int a", that's an argument to the method (something that gets passed in as input). So if you wanted to call your Test method, you would have to pass in an int, and inside the method you would refer to that int as a.
|
|
|
|
|
on you [age you have somethink like this:
public class nameOfYouClass{
static void main(String[]args)throws Exception{
}
}
If ou want create new class you may create new class write somethink like this:
public class nameOfYouClass{
static void main(String[]args)throws Exception{
nameOfYouNewClass nameOf = new nameOfYouNewClass();
nameOf.newMethod();
}
}
class nameOfYouNewClass{
public void newMethod(){
System.out.println("Hello Workd!!");
}
}
and you will create new Object with method called newMethod.
If you want use class nameOfYouNewClass just create this class in the you main function. And you may use methods from this class(object)
|
|
|
|
|
Work your way through these tutorials[^], and all your questions will be answered.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
I have this the code below:
I used this code based in HashSet to remove duplicates but does not work:
public static <Enterprise> void removeDuplicates(ArrayList<Enterprise> list) {
HashSet<Enterprise> h = new HashSet<Enterprise>(list);
list.clear();
list.addAll(h);
}
public static void main(String args[]) {
ArrayList<Enterprise> array = new ArrayList<Enterprise>();
array.add(new Enterprise("Micro System", 2001));
array.add(new Enterprise("Delta Force", 1980));
array.add(new Enterprise("Micro System", 2001));
array.add(new Enterprise("Golden Mayer", 1781));
removeDuplicates(array);
for (Enterprise item : array) {
System.out.println(item);
}
}
}
public class Enterprise {
private String name;
private int yearFondation;
public Enterprise(String name, int yearFondation) {
this.name = name;
this.yearFondation = yearFondation;
}
public String getname() {
return name;
}
public int getYearFondation() {
return yearFondation;
}
public void setname(String name) {
this.name = name;
}
public void setYearFondation(int yearFondation) {
this.yearFondation = yearFondation;
}
@Override
public String toString() {
return "Enterprise : " + name + " Year of Fondation : " + yearFondation;
}
}
|
|
|
|
|
Enterprise is a class, so when you call
array.add(new Enterprise("Micro System", 2001));
twice, you are actually adding two different Enterprise objects to array; they just happen to have the same data.
If you want the identical objects to be treated as if they were the same object, unfortunately I don't recall how HashSet does the comparisons, but I'm guessing you'll either have to override equals or hashCode on the Enterprise class.
|
|
|
|
|
It does comparisons with equals and hashCode, yes. And if you override one you should override the other.
|
|
|
|
|
If you generate hashCode() and equals() in Enterprise class all must works. If you use Eclipse go into Source - > Generate hashCode() and equals()... and Eclipse will generate this code instead of you, if you don't know how to do this.
|
|
|
|
|
Hi People!
I search a educational imap client project without api´s.
Thanks!
|
|
|
|
|
|
I'm rolling my own text system, or trying to anyways...
I cycle through the bitmap to determine the texture coordinates of every character. Then add them to the map via their associated char. Later I cycle through a string to pull the texture coords and add them to the buffer... the coords are correct going in but not pulling out.
private HashMap<Character, float[]> glyphs = new HashMap<Character, float[]>();
glyphs.put(c[i], temp);
float temp[] = glyphs.get(a);
The array returned is the same one for every char sent to the retrieval function. I must be doing this wrong... any help?
EDIT: The coord to be retrieved is the coord of the last thing put into the map.
modified 2-May-12 18:27pm.
|
|
|
|
|
Figured it out... <.>
I wasn't instantiating a new temp each pass. So the last element is stored for every key. Easy fix, just re-instantiate the variable before setting a value and calling put()
|
|
|
|
|
snap! You got it while I was typing (and taking a phone call....)
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Np, thanks for trying. ^^
|
|
|
|
|
I can't see the rest of your code, but it smells like you are reusing the same temp , effectively overwriting the same item on every put() .
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Yup, had just posted that. XD Thank you though ^^
|
|
|
|
|
When I was compiling one of my java program i got the error to recompile with -Xlint ? I m unknown to this can anybody help and xplain that what is -Xlint?
|
|
|
|
|
|
Have project that requires fix protocol over tcp and encryption, need userinterface gui made as well. skype me at: silverbuyer or email me canadametalsauction@gmail.com
|
|
|
|
|
ByteBuffer pixel = ByteBuffer.allocateDirect(1);
byte transparentByte = 0;
gl.glBindTexture(GL10.GL_TEXTURE_2D, _id);
pixel.position(0);
gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, x, y, 1, 1, GL10.GL_ALPHA, GL10.GL_UNSIGNED_BYTE, pixel); pixel.position(0);
if(pixel.get() != transparentByte)
{
}
This never hits... It'll cycle through every pixel in the texture and never hit on a non-transparent pixel. What am I doing wrong?
EDIT: It looks like whether or not I use GL_ALPHA or GL_RGBA, pixel.get() returns 0 for every pixel... it's not grabbing it from the texture or I'm not using ByteBuffer correctly... hmm...
modified 1-May-12 22:11pm.
|
|
|
|
|
Well... I fixed my problem by just not using OpenGL so the question still stands for anyone who comes across this thread.
modified 2-May-12 13:42pm.
|
|
|
|
|
I have a list of objects, and I need to output them in a JTable. In order to do this, I am trying with a while loop.
Without the while loop, rows are inserted. On the other hand, using the while loop, the applications goes inside the loop but it does not effect the JTable output.
Code used
DefaultTableModel starModel = new DefaultTableMode();
int starCounter = 0;
while (starCounter < list.size()){
starModel.addRow(new Object[]{"test"})
}
jtableVariable = new JTable(starModel);
Pawlu89
|
|
|
|
|
i) you never increment the counter, so this is an infinite loop
ii) ... unless the list has zero items in which case you won't get any rows.
|
|
|
|
|
Thanks....on the other hand I solved the problem by doing an action listener on another object. Thanks anyways, thought something was missing.
|
|
|
|