Home Answers Viewqa Java-Beginners Java GUI IndexOf

 
 


Nikolas F
Java GUI IndexOf
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners

View Answers

December 3, 2009 at 2:48 PM


Hi Friend,

Try the following code:

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

public class CountCharacters extends JFrame{
JLabel l1,l2;
JTextField text;
JTextArea area;
JScrollPane pane;
JPanel panel;
JButton button;

CountCharacters(){
l1=new JLabel("Enter text: ");
l2=new JLabel("Charcter to Search: ");
text=new JTextField(10);
area=new JTextArea(3,4);
pane=new JScrollPane(area);
panel=new JPanel(new GridLayout(3,2));
button=new JButton("Search");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=area.getText();
char searchedChar=text.getText().charAt(0);
count(searchedChar,st);

}
});
panel.add(l1);
panel.add(pane);
panel.add(l2);
panel.add(text);
panel.add(button);
add(panel);
setVisible(true);
pack();
}
public int count(char c, String str) {
if (str == null) return 0;
int cnt = 0;
for (int i = 0;; cnt++) {
if ((i = str.indexOf(c,i)+1) == 0) break;
}
JOptionPane.showMessageDialog(null,"Character "+c+" occurs "+cnt+" times");
return cnt;
}
public static void main(String[]args){
CountCharacters chars=new CountCharacters();
}

}

Thanks









Related Pages:
Java GUI IndexOf - Java Beginners
Java GUI IndexOf  Hello and thank you for having this great site. Here is my problem. Write a Java GUI application called Index.java that inputs several lines of text and a search character and uses String method indexOf
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
indexof case insensitive java
indexof case insensitive java  Hi, I have to use the indexOf function on String class in Java. I am looking for indexof case insensitive java... the string into lowercase and then use indexOf method as shown below: String s1
Java ArrayList indexof() Method
. If no element is present then returns the -1. Example of Java Arraylist indexof() Function import java.util.*; public class List1 { public
String indexOf() Method
String indexOf() Method      ... the indexOf() method of String class. We are going to use indexOf() method of String class in Java. The description of the code is given below for the usage
java gui
java gui   friends... good day.. i have doubt in java gui. ? i created 1 java gui application. That has two text fields jtext1,jtext2. case: user entered value in first textfield(jtext1) and pressed the enter key . the cursor
String indexOf(String str)
about the indexOf(String str) method through the following java program... String indexOf(String str)     ... the indexOf(String str) method of String class. We are going to use indexOf(String str
Java GUI
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
String indexOf(int ch)
the indexOf(int ch) method through the following java program. In the program... String indexOf(int ch)      ... the indexOf(int ch) method of String class. We are going to use indexOf(int ch
Programming - Transform Name - GUI 0
Java: Programming - Transform Name - GUI 0 Write a GUI program to redisplay a name, possibly transformed. This Java program will reformat a user's name...: Michael Maus Output: Maus, Michael The tring methods are indexOf
Java GUI
Java GUI  difference between swing and applet
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
String indexOf(int ch, int fromIndex)
about the indexOf(int ch, int fromIndex) method of String class. We are going to use indexOf(int ch, int fromIndex) method of String class in Java... String indexOf(int ch, int fromIndex)   
String indexOf(String str, int fromIndex)
explanation about the indexOf(String str, int fromIndex) method of String class. We are going to use indexOf(String str, int fromIndex) method of String class in Java... String indexOf(String str, int fromIndex)   
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Java GUI - Java3D
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA PROGRAMMES
java gui-with jscroll pane
java gui-with jscroll pane  Dear friends.. I have a doubt in my gui application. I developed 1 application. In this application is 1 Jscrollpane of height 600 and width 400. Normally it is showing 200 height and 400 width
java gui-with jscroll pane
java gui-with jscroll pane  Dear friends.. I have a doubt in my gui application. I developed 1 application. In this application is 1 Jscrollpane of height 600 and width 400. Normally it is showing 200 height and 400 width
GUI problem - Java Beginners
GUI problem  how to write java program that use JTextField to input data and JTextField to display the output when user click Display Button??  Handle the actionPerformed event for JButton and try doing something like
Java GUI - Java Beginners
Java GUI  How to use JTray in java programme?  Hi friend, JTrayIcon jtc= new JTrayIcon(image); // jPopupMenu is a javax.swing.JPopupMenu jtc.setRightClickTarget(jPopupMenu); jtc.show(); Thanks
Gui Interface - Java Beginners
Gui Interface  hi I have two seperate interfaces in the same projects . my question is how can I access this interface using a jbutton (i.e jbutton = next where next points to another interface addCourse.java) What would
GUI 2 - Java Beginners
GUI 2  How can I modify this code? Please give me a GUI...;GUI Example");pack();show();}public void actionPerformed(ActionEvent event... world and like it alot. I was wondering where can I go to learn more about java
GUI - Java Beginners
GUI testing  GUI testing in software testing  HiNow, use the code and get the answer.import javax.swing.*;public class DemoTryCatchDialog...;GUI Example");pack();show();}public void actionPerformed(ActionEvent event
java gui - Java Beginners
java gui  i have to create dynamically databse,table, and number of field..inside that field dynamically data can be entered with type of variable..after entering all the dat in different form field label,i should have a button
Java GUI code
Java GUI code  Write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited: 80000.00 Years: 15 Interest rate: 7.75 Total Amount: Hint** to solve this problem
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
Java GUI - Applet
Java GUI  HELLO, i am working on java chat server, i add JFrame and make GUI structure by draging buttons and labels, now i want to insert... but not resolve my prob. dear friend, i add JFrame Form in java package and put
how to refresh my GUI page
how to refresh my GUI page  how to refresh a GUI in java
GUI Interface - Java Beginners
GUI Interface  Respected sir, please send me the codimg of basic... and multiplication. But use classes javax swing java awt java awt.event no other...://www.roseindia.net/java/ Thanks
Java: Basic GUI
Java NotesBasic GUI Next - Big Blob This first example just shows what... 16 17 18 // structure/CalcV1.java // Fred Swartz - December 2004 // GUI Organization: All work is in the GUI constructor. // // (1) Main creates
GUI Alternatives
, it isn't difficult to build a Graphical User Interface (GUI) in Java, but it is hard... to use the Java GUI libraries to build your GUI. There are alternatives... your interface be in Java? You can use existing GUI technologies like Flash
java gui database - Java Beginners
java gui database  I have eight files. Each file has exactly same... the data on command line but I do not know how to display the same using java gui. Could anybody help me. Thanks. Shah
GUI - Java Beginners
links: http://www.roseindia.net/tutorial/java/swing/navigatedata.html http://www.roseindia.net/java/example/java/swing/add_edit_and_delete_employee_inf.shtml
Component gui - Java Beginners
Component gui  Can you give me an example of Dialog in java Graphical user interface?  Hi friend, import javax.swing.*; public...://www.roseindia.net/java/example/java/swing/ Thanks
GUI Tips
Java NotesGUI Tips [Beginning of list of GUI tips -- needs much more.... Events and communication After the GUI is constructed, the program stops execution... (eg, actionPerformed) may be mixed in with the GUI construction code
Java scroll pane-java GUI
Java scroll pane-java GUI  Dear friends.. Very Good morning. I have a doubt in my gui application. Take ex:- My gui application has 1 Jscrollpane of height 600 and width 400. normally it is showing 200 height and 400 width
java GUI program - Java Beginners
java GUI program  java program that creates the following GUI, when user enter data in the textfield, the input will be displayed in the textarea...://www.roseindia.net/java/ Thanks. Amardeep
convert this code to GUI
of the book: "); oldAuthor=catalog.get(newAuthor.name.charAt(0)).indexOf(newAuthor...(author.name.charAt(0)).indexOf(author); if(authorIndex==-1) System.out.println("Misspelled...(0)).indexOf(patron); if(patronIndex==-1){ patron.books.add(bookToCheckOut
covert this code to GUI
=catalog.get(newAuthor.name.charAt(0)).indexOf(newAuthor); if(oldAuthor==-1...(author.name.charAt(0)).indexOf(author); if(authorIndex==-1) System.out.println...; patronIndex=people.get(patron.name.charAt(0)).indexOf(patron); if(patronIndex==-1

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.