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



Home Answers Viewqa Java-Beginners GUI application program

Have Programming Question? Ask it here!
 
 
 


Rajbir Bhullar
GUI application program
1 Answer(s)      a year and 9 months 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
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 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
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
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
GUI Java JSP application  GUI Java JSP application
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
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 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
GUI framework
GUI framework  what do u mean by GUI framework
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
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
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop 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
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
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
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
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
Java scroll pane-java GUI
Java scroll pane-java GUI  Dear friends.. Very Good morning. I have a doubt in my gui application. Take ex:- My gui application has 1 Jscrollpane... my program.... Thanks dears in advance
Find Array element from index using GUI
Find Array element from index using GUI In this tutorial, you will learn how to create an GUI application to find an array element from its index. For this, we have created an an array of 100 randomly chosen integers and allow
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
GUI problem - Java Beginners
GUI problem  how to write java program that use JTextField to input data and JTextField to display the output when user click Display Button??  Handle the actionPerformed event for JButton and try doing something like
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
how to refresh my GUI page
how to refresh my GUI page  how to refresh a GUI in java
Java GUI code
Java GUI code  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 Total Amount: Hint** to solve this problem
 

 

 

DMCA.com