The Artima Developer Community
Sponsored Link

Java Answers Forum
Tick Color for JCheckBox

3 replies on 1 page. Most recent reply: Aug 7, 2005 11:40 PM 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 3 replies on 1 page
Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Tick Color for JCheckBox Posted: Aug 1, 2005 3:17 AM
Reply to this message Reply
Advertisement
Anyone have any idea how to set the Tick or selector
Color for a JCheckBox (setForeground will not work
here)?


madevil

Posts: 3
Nickname: madevil
Registered: Aug, 2005

Re: Tick Color for JCheckBox Posted: Aug 7, 2005 12:24 AM
Reply to this message Reply
Im sorry, i don't know how to get to u. I saw ur reply to ogeela and sabrina's question.
Its the same as mine but they wrote the codes wrongly. This is the real thing. Pls c if u can help.
Thank u.

Task 1
------
Class, Inheritance, String Processing, Sorting, Searching
 
Consider the code:
------------------
 
public class Meth1
 
{
	public static boolean words(String[]p,String[]q)
 
	{
	boolean flag=true;
 
	for(int i=0;(i<q.length && flag);i++)
	flag=(look(p,q[i]));
 
	return flag;
}//words
	
	public static boolean look(String[]p,String w)
	{
 
	boolean flag=false;
 
	for(int i=0;(i<p.length && !flag);i++)
	if (p[i].equals(w))flag=true;
 
	return flag;
	}
 
}//Meth1
 
 
 
a) Work out and document the processes being carried out by the method "words"
   in the above class. Your documentation should include any data used for this purpose.
 
Tips:
-----
 
import java.io.*;
 
public class TestMeth1
{
	public static void main(String args[])
	{
		String w1[]={"cast","static","thread","make","void","import"};
		String w2[]={"import","cast","static"};
 
		Meth1 m = new Meth1();
 
System.out.println(m.words(w1,w2));
 
}//main
 
 
 
b) A client has an array of English words. What is required to list all those words
   from the array, which come alphabetically after the word "make", and they are to
   appear in alphabetical order.
   For example, given an array of words as shown below:
 
   cast    static    thread    make    void    import
 
   should produce an array of words:
 
   static    thread    void
 
   Use inheritance to extend the class "Meth1" to provide the necessary methods
   which achieves the specified requirement.
 
Tips: 
-----
 
//Do inheritance with Task 1 a)
 
{
	void sortWords(...)
 
	{
   	 .
   	 .
	 .
  	}
 
	void displayAll(...)
 
	{
   	 .
   	 .
   	 .
  	}
 
	void displayFrom(String w[], String point)
 
	{
   	 .//if point exist in String w[], output all words after "make"  
   	 .//else, error message.
   	 .
  	}
} 
 
 
public class TestTask1b
{
	public static void main
	{
	 Task1b t = new Task1b();
	 .
	 .
	 .
	}
}
 
THE END
 

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Tick Color for JCheckBox Posted: Aug 7, 2005 11:34 PM
Reply to this message Reply
Because you actually took the time to format your code,
I will assist you with your homework (clearly this
is a homework problem - am I wrong?)

> Im sorry, i don't know how to get to u. I saw ur reply to
> ogeela and sabrina's question.
> Its the same as mine but they wrote the codes wrongly.
> This is the real thing. Pls c if u can help.
> Thank u.
>
>
> Task 1
> ------
> Class, Inheritance, String Processing, Sorting, Searching
> 
> Consider the code:
> ------------------
> 
[pre]
 public class Meth1
 
 {
 
        /*
         * @description:   This method ensures that every
         *                 word in array q exists in p
         * @returns:       true if everything in q has
         *                 an equivalent word in p
         */
 	public static boolean words(String[]p,String[]q)
 
 	{
        //  initially set to true;
 	boolean flag=true;
   
      //  self explanatory for loop
 	for(int i=0;(i<q.length && flag);i++)
 	flag=(look(p,q[i]));
 
        //  was I found (if true at the end
        //  every word in q is available in p
 	return flag;
}//words
 	
 
        /*
         * @description:  does w exist in array of words p,
         * @returns:      true if answer to above q is yes
         */
 	public static boolean look(String[]p,String w)
 	{
 
 	boolean flag=false;
 
 	for(int i=0;(i<p.length && !flag);i++)
 	if (p[i].equals(w))flag=true;
 
 	return flag;
 	}
 
}//Meth1
 
 
[/pre]
&gt; 
&gt; a) Work out and document the processes being carried out
&gt; by the method "words"
&gt; in the above class. Your documentation should include
&gt; ude any data used for this purpose.
&gt; 
&gt; Tips:
&gt; -----
&gt;
 
&gt; import java.io.*;
&gt; 
&gt; public class TestMeth1
&gt; {
&gt; 	public static void main(String args[])
&gt; 	{
&gt; String
&gt; ng
&gt; w1[]={"cast","static","thread","make","void","import"};
&gt; 		String w2[]={"import","cast","static"};
&gt; 
&gt; 		Meth1 m = new Meth1();
&gt; 
&gt; System.out.println(m.words(w1,w2));
&gt; 
&gt; }//main
&gt; 
&gt; 
&gt; 
&gt; b) A client has an array of English words. What is
&gt; required to list all those words
&gt; from the array, which come alphabetically after the
&gt; the word "make", and they are to
&gt;    appear in alphabetical order.
&gt;    For example, given an array of words as shown below:
&gt; 
&gt;    cast    static    thread    make    void    import
&gt; 
&gt;    should produce an array of words:
&gt; 
&gt;    static    thread    void
&gt; 
&gt; Use inheritance to extend the class "Meth1" to provide
&gt; ide the necessary methods
&gt;    which achieves the specified requirement.
&gt; 
&gt; Tips: 
&gt; -----
&gt; 
&gt; //Do inheritance with Task 1 a)
&gt; 
&gt; {
&gt; 	void sortWords(...)
&gt; 
&gt; 	{
&gt;    	 .
&gt;    	 .
&gt; 	 .
&gt;   	}
&gt; 
&gt; 	void displayAll(...)
&gt; 
&gt; 	{
&gt;    	 .
&gt;    	 .
&gt;    	 .
&gt;   	}
&gt; 
&gt; 	void displayFrom(String w[], String point)
&gt; 
&gt; 	{
&gt; .//if point exist in String w[], output all words
&gt; words after "make"  
&gt;    	 .//else, error message.
&gt;    	 .
&gt;   	}
&gt; } 
&gt; 
&gt; 
&gt; public class TestTask1b
&gt; {
&gt; 	public static void main
&gt; 	{
&gt; 	 Task1b t = new Task1b();
&gt; 	 .
&gt; 	 .
&gt; 	 .
&gt; 	}
&gt; }
&gt; 
&gt; THE END
&gt; 
&gt; 


For the above run a google on sort algorithms,
sort String array, that should help you sort
the given array and fill in the method


void sortWords(String []words){

}


once words is sorted have another method


/* make sure you pass in the correct array
* that you have just sorted as argument words
* when calling it
*/
private int indexOfMake(String []words){
int i = 0;
for(i = 0; i < words.length; i++){
if(words[i].equals("make")
return i;
}
return i;
}



when you call this you will call

int makeIndex = indexOfMake(words);
run through this array with a for loop and
only add to a new array, the array elements
for which: i > makeIndex;

public String[] retrieveMakeArray(String []words){
int sizeOfNewArray = words.length - makeIndex+1;
String [] newArray = new String[sizeOfNewArray];
int j = 0;
for(int i = makeIndex+1; i < sizeOfNewArray; i++){
newArray[j] = words[i];
j++;
}
return newArray;
}
[pre]

sortedArray = retrieveMakeArray(words);

I think I've pretty much done 70% of your homework.
Ask your prof to credit me, now I gotta get back to
coding significant things.

Spike

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Tick Color for JCheckBox Posted: Aug 7, 2005 11:40 PM
Reply to this message Reply
p/s: If your not responding or giving a suggestion to
the OPs thread please start a new one, it was a weekend,
so obviously the response rate would be low (most of
us spend our weekends drinking beer, or by other means
of entertainment).

Flat View: This topic has 3 replies on 1 page
Topic: Compiling Bruce Eckel's "Thinking in Java" source code Previous Topic   Next Topic Topic: auto responders

Sponsored Links



Google
  Web Artima.com   

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