Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java GUI IndexOf
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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 Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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
Java GUI
Java GUI  difference between swing and applet
String indexOf() method in Java
String indexOf() method in Java In this tutorial we will discuss about indexOf() method in java. indexOf() method which is of string class,  used... for searching a specified character or string, indexOf() and lastIndex(). For example
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
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
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
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
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA PROGRAMMES
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
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
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
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 - 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
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 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
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 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
Chat in Java wih GUI
Chat in Java wih GUI  Welcome all >> << how is everybody >< i wanna Chat program in java server & client thanks
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
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
MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java  i wanna MultiClient-server tcp-ip with GUI in java
GUI testing/software testing - Java Beginners
GUI testing/software testing  how to create a GUI testing/software testing module in java
MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java  i wanna MultiClient-server tcp-ip with GUI in java
Advertisements
 

 

 

DMCA.com