Melanie Walsh

Greenhorn
+ Follow
since Dec 14, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Melanie Walsh

Hi
I have been pulling my hair out with this problem. Every time i use a JTextField instead of adding one thing, it adds the string typed into to the object set in action listener but then it adds an empty object. This has had me baffled for over a week. I have tested the Add methods in the calling class and they work fine, it only happens when i try and pass text using an action listener.
I am using JDK 1.5 i dont know if it something different in there but can someone please put me out of my misery.
This is the action listener that extracts the text, also the method it calls - thanks guys


<Code>
class AddUserActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

String nameIn = newUserField.getText();
if(nameIn != null)
{
fc.addUser(nameIn);
newUserField.setText("");

JOptionPane.showConfirmDialog(null, nameIn + " has been Added", "Confirmation", 2, 2);
setVisible(true);
}


}
}


public boolean addUser(String nameIn)
{
boolean userAdded = false;
Favourites tempFav = new Favourites();


if(nameIn != null & favIn != null)
{
tempFav.setName(nameIn);
favIn.add(tempFav);
userAdded = true;
System.out.println("User Added :- " + tempFav.getName());
System.out.println("All Users:-" + getUsersNames().toString());


}
/*else
{
favIn = new ArrayList<Favourites>();
usersFavourites.setName(nameIn);
favIn.add(usersFavourites);
userAdded = true;
System.out.println("User Added :- " + usersFavourites.getName());
System.out.println("All Users:-" + getUsersNames().toString());
//writeFavourites();

}*/
System.out.println("The current favourites are " + favIn.toString());
writeFavourites();
return userAdded;
}

</Code>
14 years ago
I have a class that implements ContentHandler, the character method looks for tags then extracts the content.
It all works well except when it finds a '[' or ']' in the content, in this case it returns just a ']', can anyone tell me why, is this a special character.
this is the code


Would be very grateful on any suggestions

ps:
Fixed the Code tags. UBB tags use [ ] not the angle brakets like in XML format. Now, you really hate those [ and ] brakets, don't you!
[ April 21, 2005: Message edited by: Madhav Lakkapragada ]
UR a star, thank you VERY much
14 years ago
i have tried every perutation and cannot get it working. I realise SimpleDateFormate returns a string but it i still cant seem to add to my combo.
I have tried the following code without success
<Code>
Date[] availTimes = new Date[24];
String[] comboString = new String[24];

public void setComboTimes(Date[] availTimes)
{
availTimes = fc.getViewingTimes();
for(int index =0; index < availTimes.length; index++)
{
SimpleDateFormat df = new SimpleDateFormat("h:a");
df.format(availTimes[index]);
comboString = ((Date)availTimes[index]);
startTimeCombo.add(comboString);
}
}
</Code>

I am at a total loss with this, i cannot understand why after formatting the combo changes back, this code is an addition to exsisting code, have tried paasing both a sting and date to the comboString - all i get is incompatible types

Any help gratefully recieved
14 years ago
Yes, im using two combo boxes which need to b populated with the 24 hours of a day. This is for my 3rd year degree project, i have all the back end functionalty, but part of my requirements state that a user may set a time Start and Finish. I need the time to do the rest of my program which will check for data then perform a filter between the hours set in start and finish.
As i said i have not trouble with the format of the hour until its passed into the combo.
14 years ago
Sorry ur system seems to have changed some text into smilies ,
the results i have from using the SimpleDateFormat are in the form h:am/pm
14 years ago
I am passing an array of 24 hours of the day into a JCombo box. I have formated my Date usinging the SimpleDateFormat class, in order to produce a list consisting of 24 hours. Looks like 1 M, 2 M etc, the trouble is when i pass this into a JCombo it looses the formatting and becomes a date object againg with full Date, Time etc in long format.
I am sure that it is beacuse to cast an array i have used the following Code
startTimeCombo = new JComboBox((Date[]) availTimes);

The 24 elements appear in the combo but in an unuasble format, can anyone help

Thanks
14 years ago
Hi
I think i have sorted that problem by using a ListIterator and casting the result of previous() back to a program object. Its working 'sort of' but whats happing now is it seems to be stuck on an endless loop. Im using the find() method to locate programs that match a users interest, trouble is when it finds something it just keeps matching the same thing over and over.
Im obviuosly not breaking out of the loop but as yet i cant find a way aroung it, thank you so much for ur input, its been great
Have the following code, can you help
<Code>
public ArrayList<Program> matchInterests()
{

fc.createFullListings();
todaysPrograms = fc.getProgramsToMatch();
matchActivator.setUsersFavourites();
boolean matchedProg = false;
favIn = matchActivator.getUsersFavourites();



ArrayList<String> usersInterests = favIn.getInterest();//this retrieves the users list of Interests
System.out.println("Users Interests found : " + usersInterests.size());//Test to c if interests are there

Iterator<String> it = usersInterests.iterator();//Iterator for Users List of Interests(Arraylist<String>

System.out.println("Programs located are:- " + todaysPrograms.size());//Test to c if currents days programs are there

try{
while(it.hasNext())//Outta Loop - Users Interests
{

String interest = (String)it.next();

programPattern = Pattern.compile(interest, Pattern.CASE_INSENSITIVE);//compile as pattern

ListIterator i = todaysPrograms.listIterator();//this gets an arraylist of programs
while(i.hasNext())// inner loop for all programs currently held in ArrayList<Program>
{

Program tempProg = (Program)i.next();
String dailyProgram = tempProg.getDescription();
Matcher matcher = programPattern.matcher(dailyProgram);

if(matcher.find())
{
System.out.println("match");
System.out.println(matcher.group()); //get the group that fired the match
Program matchedProgs = ((Program)i.previous()); //Cast the matched program back to a temp program
System.out.println("Program Matched is :- " + matchedProgs);
matchedPrograms.add(matchedProgs);//add each match to new array list - yippee
System.out.println("The following program have been found:- " + matchedPrograms.toString());
matchedProg = true;
//matchedPrograms.add(match);
}//else
//System.out.println("No Match Found!!");
}
}


}catch (PatternSyntaxException pse)
{
System.out.println("Syntax error!!");
System.exit(1);
}
return matchedPrograms;
</code>

Thank you
14 years ago

Ive sorted the problem, how silly do i feel,
the following code does exactly what i need, ur a star thank u for ur help
<Code>
if(matcher.matches())
{
System.out.println("match");
System.out.println(matcher.group());
Program matchedProgs = ((Program)i.next());
System.out.println("Program Matched is :- " + matchedProgs);
matchedProg = true;
//matchedPrograms.add(match);
}//else
//System.out.println("No Match Found!!");
14 years ago
Hi
Can i ask one last question, i can obtaim the program title from the matcher.group()method, what im trying to do is when a match is found i need to capture the program object that fires the match
ie. a Program object has a startTime, Title, Desc..
Its late now so im probably not thinking clearly but is there a was of backtracking to capture all attributes of the Program or am i stuck with the title?
Thanks again,
14 years ago
Wow thank you so much , its works. Im really grateful for your help. Thanks a million.
14 years ago
Hi
Ive re-checked my code and i am calling the users favourite programs as the otta loop. I think the problem lies when i iterate through the current arraylist of Program objects.
I have put comments in my code to try and explain what im attempting to do, but i think its a casting issue, would be grateful for any help

Iterator i = todaysPrograms.iterator();//this gets an arraylist of programs

ArrayList<String> usersPrograms = favIn.getFavProgs();
//this retrieves favourites programs stored by user

System.out.println("Users favourites found : " + usersPrograms.size());
//Test to c if programs are there

Iterator<String> it = usersPrograms.iterator();
//Iterator for Users set of programs(Arraylist<String>

System.out.println("Programs located are:- " + todaysPrograms.size());
//Test to c if currents days programs are there

try{
while(it.hasNext())//Outta Loop - Users favourite programs
{
String program = (String)it.next();
//I am trying to cast a Program object into a String to perform
// Matching - i think this is the problem

programPattern = Pattern.compile(program, Pattern.CASE_INSENSITIVE);
//compile as pattern

while(i.hasNext())
// inner loop for all programs currently held in ArrayList<Program>
{
Matcher matcher = programPattern.matcher((String)i.next().toString());

if(matcher.find())
{
System.out.println("match");
matchedProg = true;
//matchedPrograms.add(match);
}else
System.out.println("No Match Found!!");
}
}
Thank you so much, this is driving me mad
14 years ago
Sorry for the lack of clarity in my posting, but you have grasped exactly what i wish to do.
Will try this - Thank you
14 years ago
Hi
Im having trouble with regex, i am trying to match elements of an arraylist with another arraylist of objects. Have tested some simple code that works on just matching a string but when i try and incorporate collections i run into trouble.
The code is as follows:-
public boolean matchPrograms()
{
//ArrayList<Program> todaysProgs = new ArrayList<String>();
//todaysProgs.add("eastenders");
//todaysProgs.add("Corrie");

//ArrayList<Program> matchedPrograms = new ArrayList<Program>();

fc.createFullListings();
todaysPrograms = fc.getProgramsToMatch();
matchActivator.setUsersFavourites();
boolean matchedProg = false;
favIn = matchActivator.getUsersFavourites();


Iterator i = todaysPrograms.iterator();
ArrayList<String> usersPrograms = favIn.getFavProgs();
System.out.println("Users favourites found : " + usersPrograms.size());
Iterator it = usersPrograms.iterator();
System.out.println("Listing located are:- " + todaysPrograms.size());

try{
while(it.hasNext())
{
String program = (String)it.next();
programPattern = Pattern.compile(program, Pattern.CASE_INSENSITIVE);
while(i.hasNext())
{
Matcher matcher = programPattern.matcher((String)i.next().toString());

if(matcher.find())
{
System.out.println("match");
matchedProg = true;
//matchedPrograms.add(match);
}else
System.out.println("No Match Found!!");
}
}


}catch (PatternSyntaxException pse)
{
System.out.println("Syntax error!!");
System.exit(1);
}return matchedProg;


}//end of method match programs


Does anyone have any thoughts on this, would i be better off using the Jakarta package
Thanks folks
14 years ago
Yes i have apache installed so php scripts are local, i have been told i can execute script using
URL localScript = new URL("http://localhost/BBC2Test3.php/?program");
URLConnection phpConnection = localScript.openConnection();
from a friend at uni but this doesnt seem to work
Will look into your suggestion. thank you
14 years ago