Home Answers Viewqa Java-Beginners Some additions for my previous question

 
 


Pam
Some additions for my previous question
2 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners

View Answers

November 21, 2009 at 5:08 PM


Hi Friend,

Try the following codes:
1)
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;
import java.math.*;

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 {
long l = Long.parseLong(value);
BigInteger bigInt = BigInteger.valueOf(l);
if(bigInt.isProbablePrime(10))
area.setText("Number is Prime");
else
area.setText("Number is not 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 {
long n = Long.parseLong(value);
long pf=0;
String pfac="";
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
pf += i;
pfac += Long.toString(i) + " ";
n = n / i;
}
}
area.setText(pfac);
}
}
});
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();
}
}

November 21, 2009 at 5:09 PM


continue....

2)
import java.util.*;

class Prime{
public static void checkPrime(long num){
long i=0;
for ( i = 2; i < num; i++) {
long n = num % i;
if (n == 0) {
System.out.println("Entered number is not Prime!");
break;
}
}
if (i == num) {
System.out.println("Number is Prime!");
}
}

}
class Factors
{
public static void findFactors(long n){
System.out.print("The prime factorization of " + n + " is: ");
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
System.out.print(i + " ");
n = n / i;
}
}
}

}
public class GUI {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("Test");
System.out.println();
System.out.println("1. check prime or not");
System.out.println("2. prime factors");
System.out.println("3. Exit");

boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:
System.out.print("Enter number: ");
long num=scan.nextLong();
Prime.checkPrime(num);
break;
case 2:
System.out.print("Enter number: ");
long num1=scan.nextLong();
Factors.findFactors(num1);
System.out.println();
break;
case 3:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Thanks









Related Pages:
Some additions for my previous question - Java Beginners
Some additions for my previous question  This is the question I posted several hours ago: "I'm trying to write a program that has a text field... for the GUI. Could anyone please help?" So my other two questions are: 1
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
Addition to my previous post - Java Beginners
Addition to my previous post  Addition to my previous question about the address book program. I need to have separate classes: CmdLineAddressBook.java AddressBook.java Contact.java Address.java Name.java
solve my question shortly
solve my question shortly  <html> <head> <script> function checkphoneNumber(number){ if(/[^\d ]/.test(number... the method you have made in script, and there are some more syntactical errors also
question
question  Sir , i have a starting trouble to start my search engine project , please help me to start my project , please send me some relevant java codes
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
question
question  following is my code to sent mail but i couldn't work with eclipse ,that have some errors .need i any set up in eclipse or tell to what can i do to work code properly. <%@ page import="java.io." import="java.lang.
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
Need the some guidence - Spring
Need the some guidence  Hi, MY name is pavan iam having mini projects in MCA these are the details reg projects below 1.project name:identical...; Hi pavan, I show your posted question but not not clear so can
Your competitor presses you to reveal some confidential information about your current or previous employer.
Situation: Your competitor presses you to reveal some confidential information about your current or previous employer.  .... The first is to really get information about competition. Some companies really
my question - EJB
my question  is it possiable to create web application using java beans & EJB's with out implementing Servlets and jsps in that java beans and EJB's
my question is related to my project viz
my question is related to my project viz   Sir, my project is based on MR tracking system developed using struts framework, it has been developed in Net Beans the whole project is working except a jsp page named dayplan.jsp
Question
Question   When there is an exception in my program how java runtime system handles
NEXT and PREVIOUS Records - JSP-Servlet
NEXT and PREVIOUS Records  Dear Sir, In my Project i have next and previous buttons at bottom of my page which is working fine.But as per our requirement next,previous buttons should be placed at top of the page as well
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  i need a mysql query to take a difference in between current time and previous time.please help me
question
question  i need a mysql query to take a difference in between current time and previous time from date time colomn in table.please help me
Need some help creating an order form.
found on the form html page are useful. My question is: can I tie them all together on one page, have them submited all at once to my email and how would I...Need some help creating an order form.  Hi there. I am looking
question
question  i need a mysql query to take a time in between current time and previous time from date time colomn in table.please help me View Answers
question
question  i need a mysql query to take a date in between current date and previous date from date time colomn in table.please help me View Answers View Answers
Some Notes on Java Programming Environments
Appendix 2: Some Notes on Java Programming Environments ANYONE WHO...-line environments. All programming environments for Java require some text... programming using both types of environments. Based on my experience, I recommend
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back. Yes. I want a page to use id of parents to do the search for the match. So... the matching tutors to the parent. I was telling you that my degree
Output Previous or Next Day of the Month
Output Previous or Next Day of the Month   Please Help! I need... the if...then...else construct and (2) to start using some of the Java API's, by using the String... they want the next day or the previous day. E.g., the user would see: Enter todays
question
question  Sir, Please help me to develop a simple search engine model in java , send me some codes
question
question  i need to select some details form database and that will displays on the same jsp page which is already contains some other details ,mustn't go to next page while i am clicking a link. have any option in jsp or java
QUESTION
QUESTION  please atach java tutorial to my email   Hello Friend, Please visit the following link: Java Tutorial Thanks
question
question  i need to select data from database using mysql+java script+html   Please specify some more details
question
question  i am using this code in my project response.sendRedirect("LoginForm1.jsp?msg=Username or Password is incorrect!"); but i wan't to hide this message from url.please help me
question
question  Sir, how to display web snippets for a perticular query for eg:web snippets for apple how to implement this concept in my java project please help me
question
question  suppose i had downloaded the zip file,extracted it in local directory so how automatically will it integrate with eclipse? i mean do i need to set some path or something
Jdbc Question
Jdbc Question  Hi. In Jdbc, if i am pointing to the database of some other machine, i mean instead of local-host i give the ip of that machine and that machine is shut down, Will my connection still work
question
question  i need to mark employees as half day absent who came after 10'o clock in my web project,so i need to know who are all late entry.if you have any idea using jsp and mysql please help me
question
to develop my java project
question
question  Sir, i am developing a video streaming PC server to j2me client system that the j2me player can playing video from PC server .if have any code for video streaming then send to my email address as soon as possible
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
question
=request.getParameter("address"); %> <html> <h3>Getting values from previous
Java Question Anyone need some HELP !!
Java Question Anyone need some HELP !!  Create a file that contains your favorite movie quote. Use a text editor such as Notepad and save the file as Quote.txt. Copy the file contents and paste them into a word-processing program
question
/) is not available.** how tdo i solve this.please help me to run my project please give
question
question  i am using this code in my project response.sendRedirect("LoginForm1.jsp?msg=Username or Password is incorrect!"); but i wan't to hide this message from url.please help me. you gave me the response Hi Jamsiya
question
;/tr> </table> this is my jsp page package servlet; import java.io.
Regarding My 3rd Question in Java - Swing AWT
Regarding My 3rd Question in Java  sir in Netbeans By default JTable Columns will appear Horizontal like Title1 Title2 Title3 Title4 in below these our data will appear so my question that is there any method
Clarify my last question's answer - Java Beginners
Clarify my last question's answer  Dear expert, I've tried out... did not specify my question too clearly. Here's my 2 database... and parents contain other fields like name, address, email, contact numbers etc. My
The Currently Running Servlet is showing some Previously run Servlet's Output
The Currently Running Servlet is showing some Previously run Servlet's Output  My question is clearly stated in the Title part of this page. Suppose for example, I have executed the ParameterServlet servlet where the output
How do I track how many hits my website gets
There are some terminologies that need to be cleared before knowing the answer of this question. Hits- this simply refers to the number of 'elements' loaded on your site. If one page has five images in it, viewing that page
Need some help urgently
number of possible combinations.   The actual question got some error. Its...Need some help urgently  Can someone please help me with this below question. I need to write a class for this. If you roll Y standard six-sided dice
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser with the help of standard widget toolkit(swt) and java. i creted some buttons such as GO... we can see as the name of all the buttons.my question is i need to change
How to launch my web application from my desktop without opening Netbeans IDE everytime i run the application?
for my previous question but i knw how to create JSP pages, I have completed my web application, now my question is how can i start my web application, wat i mean...How to launch my web application from my desktop without opening Netbeans IDE
PLZ Need some help on the 2nd part of this question...Someone please help !!!!
PLZ Need some help on the 2nd part of this question...Someone please help !!!!  write an application that displays a menue of three items in a restaurant as follows: 1.Cheeseburger 4.99 2.Pepsi 2.00 3.Chips 0.75 prompt the user
referring to question Person.. - Java Beginners
=gender; this is base on previous question (Person)..can u explain to me...referring to question Person..  Hi!firstly i want to thank to someone who always answer my questions, i really appreciate it..emm may i know what

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.