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



Home Answers Viewqa Java-Beginners Writing a GUI program

Have Programming Question? Ask it here!
 
 
 


Pam
Writing a GUI program
1 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners



Advertisement
View Answers

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 Beginners
Writing 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 program
GUI 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 Beginners
writing 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
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.   Hi friend, import javax.swing.*; import
writing program in bluej - Java Beginners
writing 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
Java GUI Program - Java Beginners
Java 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
Need help writing a console program
Need 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
want a program for cd writing in java - Java Beginners
want a program for cd writing in java  Hi Can u tell some body, doing a program on cd writing in java. I m facing some problem on it. Thanks in advance. Regards sanjaya
Java gui program for drawing rectangle and circle
Java 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
GUI convert to celsius program - Java Beginners
GUI 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
need help on writing a program. - Java Beginners
Writing 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 program
Need 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 program
Need 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 program
Need 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 Beginners
java 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
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
without writing web.xml file we can write servlet program
without writing web.xml file we can write servlet program  Sir Morning... Sir I have one Question "without writing web.xml file we can write servlet program". if yes which way? if no why? but without use Annotation........ Plz
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write a program to read data from a file. Then use the numerical data within
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write a program to read data from a file. Then use the numerical data within
I am writing a program which converts a string to a timestamp and add days to it
I am writing a program which converts a string to a timestamp and add days to it  java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2012-01-11 12:34:39"); long l=ts2.getTime() +(100060602424);//add 24 days Date d=new Date(l
Having a hard time writing program to calculate test scores..........
Having a hard time writing program to calculate test scores..........  i need a program that does this:Standardized Test Scores A local high... to have your program open the data file, count the number of elements in the file
How can I write a GUI stack program by Java to push Image files instead of other data type items?
How can I write a GUI stack program by Java to push Image files instead of other data type items?   How can I write a GUI stack program by Java to push Image files instead of other data type items? for the push instruction I
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... be good extra credit for this program. You can easily use the Java functions
Writing Simple Java Script Program
Writing Simple Java Script Program   ... of JavaScript and create your first JavaScript program. Creating your first JavaScript Program In the last lesson you learned how to create simple java script
i written the program in the files but in adding whole file is writing once again - Java Beginners
i written the program in the files but in adding whole file is writing once again  Very Urgent: Write a small record management application file and it should not be re-written for every add/delete operation.  Hi
GUI problem
GUI 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
GUI framework
GUI framework  what do u mean by GUI framework
GUI component
GUI component  How can a GUI component handle its own events
gui question
gui 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
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
Convert the code to GUI
GUI code  GUI code
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
gui question
gui question  design a gui application and write code to accept a string from the user in a textfeild and print using option pane whether it is a palindrome or not. hint: abba is a palindrome   import java.awt.*; import
Convert the code to GUI
GUI Application example  GUI Application example
Convert the code to GUI
GUI Example  GUI Example code to learn
GUI problem
GUI problem  How do I make a Jbutton which is shaped like a circle. This button needs to be clicked in order to change color.   import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class
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 Tips
. Events and communication After the GUI is constructed, the program stops execution... Java NotesGUI Tips [Beginning of list of GUI tips -- needs much more] Program structure main can be in any class, but it's often simplest
Blog Writing
Blog 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
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
GUI Application Development   GUI Application Development
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Writing Actions
Writing 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
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
 

 

 

DMCA.com