November 21, 2009 at 2:55 PM
Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;
class GuiApplication extends JFrame {
JLabel label1, label2;
JTextField text;
JTextArea area;
JScrollPane pane;
JPanel panel, panel1, panel2;
JButton button1, button2;
GuiApplication() {
panel = new JPanel(new GridLayout(3, 2));
panel1 = new JPanel(new GridLayout(3, 2));
panel2 = new JPanel(new GridLayout(3, 2));
label1 = new JLabel("Enter number");
label2 = new JLabel("Result is");
text = new JTextField(15);
area = new JTextArea(2, 2);
pane = new JScrollPane(area);
button1 = new JButton("Check");
button2 = new JButton("Prime Factors");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String value = text.getText();
int i = 0;
Pattern p = Pattern.compile("[A-Z,a-z]");
Matcher m = p.matcher(value);
if (m.find()) {
JOptionPane.showMessageDialog(null,
"Please enter only numbers");
} else {
int num = Integer.parseInt(value);
for (i = 2; i < num; i++) {
int n = num % i;
if (n == 0) {
area.setText("Entered number is not Prime!");
break;
}
}
if (i == num) {
area.setText("Number is Prime!");
}
}
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String value = text.getText();
Pattern p = Pattern.compile("[A-Z,a-z]");
Matcher m = p.matcher(value);
if (m.find()) {
JOptionPane.showMessageDialog(null,
"Please enter only numbers");
} else {
int num = Integer.parseInt(value);
int perfectNo = 0;
String perfect = "";
area.setText("Factors are:");
for (int i = 1; i < num; i++) {
if (num % i == 0) {
perfectNo += i;
perfect += Integer.toString(i) + " ";
System.out.println(i);
}
}
area.setText(perfect);
}
}
});
panel1.add(label1);
panel1.add(text);
panel1.add(button1);
panel1.add(button2);
panel2.add(label2);
panel2.add(pane);
panel.add(panel1, BorderLayout.NORTH);
panel.add(panel2, BorderLayout.SOUTH);
add(panel);
}
public static void main(String[] args) {
GuiApplication app = new GuiApplication();
app.setVisible(true);
app.pack();
}
}
Thanks
Related Tutorials/Questions & Answers:
Writing a GUI program - Java BeginnersWriting a
GUI program Hello everyone!
I'm trying to write a
program... if that number is prime or not. When the second button is pressed the
program... to write the code for the
GUI. Could anyone please help? Hi Friend
GUI application programGUI application program Write a
GUI application
program that meets the following requirements:
Create an array with 100 randomly chosen integers.
Create a textfield to enter an array index and another textfield to display
Advertisements
writing program - Java Beginnerswriting program WAP to input Name of Cricketer, Number of matches, total runs scored for 250 players from the user and print data in descending order of their average runs using bubble sort. Average runs=total runs divided
writing angularjs hello world program tutorials. I want to make simple
program and thinking to start from the Hello World
program in AngularJS.
Searching for simple example for
writing angularjs...
writing angularjs hello world program Hi,
I just started to learn
writing program in bluej - Java Beginnerswriting program in bluej How to write the
program on follwing
WAP to inpout a string and print
Input : I stidied Hard
Hi Friend,
Try the following:
import java.util.*;
public class UserInput{
public
Need help writing a console programNeed help
writing a console program I need help cant seems to figure it out!
Write a
program that consists of three classes. The first class will be the actual
program.
The second class will simply convert a string to lower
java GUI program - Java Beginnersjava
GUI program java
program that creates the following
GUI, when user enter data in the
textfield, the input will be displayed in the textarea.
Hi friend,
import javax.swing.*;
import
Java GUI Program - Java BeginnersJava
GUI Program How is the following
program supposed to be coded?
Write an application that prompts the user to enter the radius of a circle by Day 7 under a thread in your Team Forum called Week Three
Program for 10 points
Java gui program for drawing rectangle and circleJava
gui program for drawing rectangle and circle how to write java
gui program for drawing rectangle and circle?
there shoud be circle....
and the
program must also show message dialog "this is a red circle" when click
need help on writing a program. - Java BeginnersWriting first Java Program Hi, I need help to write my first Java
Program other then Hello World! Thanks!! Hi Thanks for choosing roseIndia to get your query solved. check given link to see the solution of your Java
Need in desperate help in writing a console programNeed in desperate help in
writing a console program Write a console
program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console programNeed in desperate help in
writing a console program Write a console
program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console programNeed in desperate help in
writing a console program Write a console
program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
java program for writing xml file - Java Beginnersjava
program for
writing xml file Good morning
i want to write values from my database(one table)into one xml file.
Like i have 3 coloumns in my table along with their values,so when click some button i need to generate one
GUI convert to celsius program - Java BeginnersGUI convert to celsius program how to write java
GUI program to convert Fahrenheit to Celsius that need user to input value of Fahrenheit then click button convert and value of Celsius will display as a output. Hi
Java GUI to build a Student Registration Program Java
GUI to build a Student Registration
Program Write a
program... in sorted order by last name.
Demonstrate the correct operation of your
program by creating a driver
program to load the student data base and the course data
GUIGUI How to
GUI in Net-beans ... ??
Please visit the following link:
http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
GUIGUI Write a
GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
Writing Simple Java Script Program
Writing Simple Java Script
Program
... of JavaScript and
create your first JavaScript
program.
Creating your first...
java script
program. To run the
program open the html file in any browser
GUI problemGUI problem Create a class called CDProgram and 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
Hint
writing characterswriting characters how to write a group of characters to a string ...
i mean for
writing single character using charAt in java
ModuleNotFoundError: No module named 'gui'ModuleNotFoundError: No module named '
gui' Hi,
My Python
program is throwing following error:
ModuleNotFoundError: No module named '
gui'
How to remove the ModuleNotFoundError: No module named '
gui' error
GUI componentGUI component How can a
GUI component handle its own events
Magic Matrix in GUIMagic Matrix in GUI I want
program in java
GUI contain magic matrix for numbers
Ghost Writing Ghost
Writing
Ghost
Writing is the kind of
writing when someone... of
writing it. So ghostwriter
is a person who works behind the scene on a
writing project
in return of certain amount. The write-ups of the writer
gui questiongui question design a
gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
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
Blog WritingBlog
Writing
A blog, the short form of web log
is an online user... on
that. But the professionals are a better choice for
writing
the blog for commercial or promotional purpose. We provides
the services of
writing blogs for the commercial
Java GUIJava 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
Writing ActionsWriting Actions
The Action is responsible for controlling of data flow within an application.
You can make any java class as action. But struts have some built in interface
and class for making action easily.
To make an Action class