Support Forums

Full Version: wher iam doing wrong ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.Event.*;

public class potpie extends JFrame{
private JList leftlist;
private JList rightlist;
private JButton move;
private String foods[] ={"pizza", "burger" , "hotdog" , "chinese", "pastry"};

public potpie(){
super("the prakhar");
setLayout(new FlowLayout());
leftlist = new JList(foods);
leftlist.setVisibleRowCount(3);
leftlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(leftlist));

move = new JButton("lets move ! :p ");


thehandler handler= new thehandler();
move.addActionListener(handler);


}
public class thehandler implements ActionListener{
public void actionPerformed(ActionEvent event){

rightlist.setListData(leftlist.getSelectedValues());


rightlist = new JList();
rightlist.setVisibleRowCount(3);
rightlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(rightlist));

}
}



}





iam getting errors on these lines -->

move.addActionListener(handler);
public class thehandler implements ActionListener{
public void actionPerformed(ActionEvent event){


I'm not a java programmer, so it might be wrong to mention a few things, but I know of which would be VERY bad for C++. You may have created a few memory leaks.

Use code tags though.
[ code ]code goes here [ /code ]

Remove the spaces after "[" and before "]" for both code tag elements though, I was using that as an example.
(01-22-2012, 05:23 PM)AceInfinity Wrote: [ -> ]I'm not a java programmer, so it might be wrong to mention a few things, but I know of which would be VERY bad for C++. You may have created a few memory leaks.

Use code tags though.
[ code ]code goes here [ /code ]

Remove the spaces after "[" and before "]" for both code tag elements though, I was using that as an example.

How do you suppose he's created a memory leak?
Creating and allocating a variable to heap memory without destroying it after use. Like I said though, I don't really do Java programming, I do Javascript, but that's entirely unrelated, and C++.
Usually memory leaks go undetected by the compiler though, right? This shouldn't prevent him from running the application.
By the compiler itself, usually yes. There are IDE's that might give you some help on detecting them though, but you can't rely on them as they aren't very accurate and can generate false warnings if you need to keep it in memory to delete it later for your specific program. And that kind of thing can't be interpreted by the IDE or the compiler as neither has a brain like we do.

But no it shouldn't prevent him from running the application. If it continually gets used though and your RAM usage maxes or gets too high then you're in danger. I've had certain instances on my computer not with my program but with games that are known to have problems with later versions of windows making bad calls and my rundll32 was increasing in memory usage at a very fast pace. Using up 2 000 000 K of my RAM before I found out through my task manager, and decided to Reboot because I was noticing slow computer use. That kind of thing is lucky for my though that my system has 8GB RAM.
my querry is solved , i used "E" instead of "e" vents , strange i dint got any error when i used Event
(01-22-2012, 06:06 PM)AceInfinity Wrote: [ -> ]Creating and allocating a variable to heap memory without destroying it after use. Like I said though, I don't really do Java programming, I do Javascript, but that's entirely unrelated, and C++.

For the most part, there is never any memory leaks in Java. Due to the way java works, it has a system of garbage collection, which works quite well. It won't dispose of a object unless it will not be uses again. So it will not throw away an object that is still needed, and this whole process is automated by the Java runtime.

Though it is still possible to get memory leaks via bad program design. Like faulty algorithms or unnecessary object references.
So not as dangerous as C++ but more like VB.net where things are taken care of for you automatically? I've only ever used Netbeans for an IDE for Java a couple times.
(01-23-2012, 01:53 AM)AceInfinity Wrote: [ -> ]So not as dangerous as C++ but more like VB.net where things are taken care of for you automatically? I've only ever used Netbeans for an IDE for Java a couple times.

Basically everything is completely taken care for you, the only way to cause an issue is by just referencing random stuff that will not be disposed until close to the end of the app. This is very similar to vb.net, but I think the .net runtime is a little more advanced, so even if your app is crappyily designed you won't get a memory leak. Also when you go over the allocated memory in vb.net you get the "Not enough memory" exception or something like that. Which happens sometimes when you are dealing with huge arrays or you screwed up on some code and it just waists memory.
Pages: 1 2