The Artima Developer Community
Sponsored Link

Java Answers Forum
Help me about code!!!

13 replies on 1 page. Most recent reply: Oct 22, 2005 4:03 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 13 replies on 1 page
boysoledad

Posts: 7
Nickname: lunar
Registered: Aug, 2005

Help me about code!!! Posted: Oct 18, 2005 6:45 PM
Reply to this message Reply
Advertisement
i have a code file about List

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import symantec.itools.awt.MultiList;

public class List_exa extends Applet {

class SymMouse extends MouseAdapter
{

public void mouseClicked(MouseEvent mouseevent)
{
Object obj = mouseevent.getSource();
if(obj == list_sim)
list_sim_mouseClicked(mouseevent);
}

SymMouse()
{
}
}

List list_sim;

public void init() {
list_sim = new List();
list_sim.addItem("Hello");
add("Earth", list_sim);
}
void list_sim_mouseClicked(MouseEvent mouseevent) {
if(list_sim.getRows() >= 0)
{
int i = list_sim.getSelectedIndex();
if(i > -1)
{
list_sim.replaceItem("Hi", i);
}

}
}
}

i want click in List string "That" and it replace string "That" within string "Hi" but when i clicked list_sim, it's not working.... Please help


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Help me about code!!! Posted: Oct 18, 2005 10:41 PM
Reply to this message Reply
Reformat your code using the java tags as shown in the "formatting your post" section.

Tapan kumar Rath

Posts: 18
Nickname: papuni
Registered: Sep, 2005

Re: Help me about code!!! Posted: Oct 19, 2005 8:35 AM
Reply to this message Reply
I really don't understand what you intended.I think the code below is what you are looking for.


import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
 
public class List_exa extends Applet {
 
	class SymMouse extends MouseAdapter
	{
		public void mouseClicked(MouseEvent mouseevent)
		{
			Object obj = mouseevent.getSource();
			if(obj == list_sim)
			list_sim_mouseClicked(mouseevent);
		}
	}
 
	List list_sim;
 
	public void init() {
		list_sim = new List();
		list_sim.addItem("Hello");
		add("Earth", list_sim);
		list_sim.addMouseListener(new SymMouse());
	}
	void list_sim_mouseClicked(MouseEvent mouseevent) {
 
		if(list_sim.getRows() >= 0)
		{
			int i = list_sim.getSelectedIndex();
			if(i > -1)
			{
				list_sim.replaceItem("Hi", i);
			}
 
		}
	}
}
 

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Help me about code!!! Posted: Oct 19, 2005 10:33 PM
Reply to this message Reply
Yes, that's exactly what I'm looking for.
I stopped looking at unformated code some time ago.


Now to your problem:

You simply messed up creating the list.

Here's the correct code:
		list_sim = new List();
		list_sim.add("Hello");
                list_sim.add("Earth");
                add(list_sim);

Note that I'm using Java 1.5, the addItem method has been deprecated, so I used the add method instead.

boysoledad

Posts: 7
Nickname: lunar
Registered: Aug, 2005

Re: Help me about code!!! Posted: Oct 20, 2005 6:36 AM
Reply to this message Reply
ah, i want click in List item "Hello" and it'll replace String "Hello" with String "Hi"

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Help me about code!!! Posted: Oct 20, 2005 7:06 AM
Reply to this message Reply
Well?
I compiled it with my modification and it worked.

Tapan kumar Rath

Posts: 18
Nickname: papuni
Registered: Sep, 2005

Re: Help me about code!!! Posted: Oct 20, 2005 8:19 AM
Reply to this message Reply
Oh boy haven't you checked my code.I have sent the whole file.It sure does works as you specified.Though you have had your deprecated methods.Just copy and paste my code I have sent.
Bye Papuni

boysoledad

Posts: 7
Nickname: lunar
Registered: Aug, 2005

Re: Help me about code!!! Posted: Oct 20, 2005 8:02 PM
Reply to this message Reply
oh thankz i'll test ur code....

boysoledad

Posts: 7
Nickname: lunar
Registered: Aug, 2005

Re: Help me about code!!! Posted: Oct 21, 2005 2:00 AM
Reply to this message Reply
import java.applet.Applet;
import java.awt.*;
import java.awt.List;
import java.awt.event.*;

public class List_exa extends Applet {

class SymMouse extends MouseAdapter
{
public void mouseClicked(MouseEvent mouseevent)
{
Object obj = mouseevent.getSource();
if(obj == list_sim)
list_sim_mouseClicked(mouseevent);
}
}

List list_sim;

public void init() {
list_sim = new List();
String a = "This is a text";
list_sim.addItem(a.substring(0, a.indexOf(" ")));
add("Earth", list_sim);
list_sim.addMouseListener(new SymMouse());
}
void list_sim_mouseClicked(MouseEvent mouseevent) {

if(list_sim.getRows() >= 0)
{

String i = list_sim.getSelectedItem();
if(i == "This")
{
list_sim.clear();
list_sim.addItem("Hi");
}

}
}
}

when i try replace ur test with String a but it's not clear and addItem --- what wrong in it?

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Help me about code!!! Posted: Oct 21, 2005 2:51 AM
Reply to this message Reply
1. Do you even read our answers? I allready told you what's wrong.


2. Why are you still unable to format your code?

boysoledad

Posts: 7
Nickname: lunar
Registered: Aug, 2005

Re: Help me about code!!! Posted: Oct 21, 2005 3:27 AM
Reply to this message Reply
But i dont know how to post code in web

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Help me about code!!! Posted: Oct 21, 2005 3:45 AM
Reply to this message Reply
on the right of the input field there is a description.

put "[ java ]" (without the spaces before your code and [ / java ] after it.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Help me about code!!! Posted: Oct 21, 2005 12:33 PM
Reply to this message Reply
Yeegads. Please, step away from the computer. Take up something in which you are interested.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Help me about code!!! Posted: Oct 22, 2005 4:03 AM
Reply to this message Reply
This ish is annoying isn't it??? Anyways man, patience is
tough to acquire.

Flat View: This topic has 13 replies on 1 page
Topic: OutOfMemoryException Previous Topic   Next Topic Topic: Java simple program help needed

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use