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 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.

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
Write a GUI application for the WebBuy Company
Write a GUI application for the WebBuy Company   Write a GUI application for the WebBuy Company that allows a user to compose the three parts... the application starts, the text area will display a message listing the options
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
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
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
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
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
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
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
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
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â... the application starts, the text area will display a message listing the options which can
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
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
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
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
Convert the code to GUI
GUI Application example  GUI Application example
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
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
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 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
GUI framework
GUI framework  what do u mean by GUI framework
Convert the code to GUI
How to create GUI application in Java   How to create GUI application 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 component
GUI component  How can a GUI component handle its own events
Convert the code to GUI
GUI code  GUI code
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
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 Example  GUI Example code to learn
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
Version of gj-gui>gj-gui dependency
List of Version of gj-gui>gj-gui dependency
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
Maven Repository/Dependency: gj-gui | gj-gui
Maven Repository/Dependency of Group ID gj-gui and Artifact ID gj-gui. Latest version of gj-gui:gj-gui dependencies. # Version... What is Apache Maven? How to create Maven Web Application
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... the window manually.....but i need this through my program...How can i show that text
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... the window manually.....but i need this through my program...How can i show that text
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
ModuleNotFoundError: No module named 'argus-gui'
ModuleNotFoundError: No module named 'argus-gui'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'argus-gui' How to remove the ModuleNotFoundError: No module named 'argus
ModuleNotFoundError: No module named 'argus-gui'
ModuleNotFoundError: No module named 'argus-gui'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'argus-gui' How to remove the ModuleNotFoundError: No module named 'argus
ModuleNotFoundError: No module named 'argus-gui'
ModuleNotFoundError: No module named 'argus-gui'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'argus-gui' How to remove the ModuleNotFoundError: No module named 'argus
ModuleNotFoundError: No module named 'bottle-gui'
ModuleNotFoundError: No module named 'bottle-gui'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'bottle-gui' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'bottle-gui'
ModuleNotFoundError: No module named 'bottle-gui'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'bottle-gui' How to remove the ModuleNotFoundError: No module named '

Ads