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



Home Answers Viewqa Java-Beginners GUI application program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Rajbir Bhullar
GUI application program
1 Answer(s)      2 years ago
Posted in : Java Beginners


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 the element at the specific index. Create a 'Show Element' Button to cause the array element to be displayed. If the specified index is out of bounds, display the message "Out of Bounds"

Use Try Catch to catch an out of bounds index and show the appropriate message.


Advertisement
View Answers

December 1, 2012 at 5:35 PM


Here is a code that finds the element from the given index of array.

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

class ShowElement extends JFrame{
JButton ADD;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
ShowElement(){
label1 = new JLabel();
label1.setText("Enter Index:");
text1 = new JTextField(20);

label2 = new JLabel();
label2.setText("Element at specific Index:");
text2 = new JTextField(20);

ADD=new JButton("Show Element");

panel=new JPanel(new GridLayout(3,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(ADD);
add(panel,BorderLayout.CENTER);
Random r=new Random(); 

final int arr[]=new int[100];
for(int i=0;i<arr.length;i++){
    int x=r.nextInt(100)+1;
    arr[i]=x;
}
ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
    try{
    String value=text1.getText();
int in=Integer.parseInt(value);
if(in>=100){
    JOptionPane.showMessageDialog(null,"Out of Bounds");
}
else{
int ele=0;
for(int i=0;i<arr.length;i++){
    if(i==in){
        ele=arr[i];
    }
}

text2.setText(Integer.toString(ele));
}
    }
    catch(Exception e){}
    }
});
}

public static void main(String arg[])
{
try
{
ShowElement frame=new ShowElement();
frame.setSize(300,300);
frame.setVisible(true);
}
catch(Exception e){
}
}
}


Related Tutorials/Questions & Answers:
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
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
Advertisements
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 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
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
create a table in access2007 from gui application using textfields and combox
create a table in access2007 from gui application using textfields and combox  I want to create a table in ms access 2007 from gui application in which when i click create button the table should get created based on textfield
I really need a tutor for Java program that has to do with multithreading and gui!
I really need a tutor for Java program that has to do with multithreading and gui!  I am looking for a Tutor to help me with a Java program, specially GUI and multithreading. If you can tutor, please email me
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
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
College Application Program
College Application Program  Please read the following carefully and submit the program code. Question # 144 A college is good if it satisfies the following conditions: Its number of students is greater than 1000. If the name
Regarding Login application program
Regarding Login application program  Hi this is shiva. iam writing a small login form using struts1.3.10 version. once iam submit the login button it shows NULLPointer Exception. I write a SOP Statement in ActionClass
Convert the code to GUI
GUI Application example  GUI Application example
How to program an application for? - Java Beginners
How to program an application for?   How do you write an application to count the number of both odd and even integers of several positive integerss? Then the final display is the total of how many odd numbers were entered
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
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
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Computer forensic application development using JAVA program
Computer forensic application development using JAVA program  Write a computer forensic application program in Java for Recovering Deleted Files and Deleted Partitions
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
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
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
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Hibernate Simple Program Using Java Application with Eclipse
Hibernate Simple Program Using Java Application with Eclipse  How to write Hibernate Simple Program Using Java Application with Eclipse? I wish to learn Hibernate using very popular Eclipse IDE. Share me the best tutorial link
write a program for complete JDBC based application
write a program for complete JDBC based application   thank you sir... based application where in the user supplies the following table as input and the program should have the facilities of Adding, Modifying, Viewing and Deleting
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 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
Ajax Chat Application,Ajax Chat Application Program,Online Ajax Chat Application
Ajax chat Application Program Ajax chat application program request to server without refreshing the web page.  In this Session you will learn the how to display massage. This program call the method 'callchat()' for the massage
 

 

 

DMCA.com