Home Answers Viewqa Java-Beginners GUI application program

 
 


Rajbir Bhullar
GUI application program
1 Answer(s)      5 months and 20 days 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.

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 Pages:
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
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
GUI Alternatives
how to connect the GUI to a Java application. Seems..., it isn't difficult to build a Graphical User Interface (GUI) in Java, but it is hard... of GUI programming simply don't scale well. Separation of concerns BAD: Mix
Rationale for GUI tutorial decisions
? No subclass. Building a GUI entirely in a static main program may... Table of Contents Rationale for GUI tutorial decisions Java offers many... learn GUI programming? All "normal" programs are GUI based, so this question
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
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
Convert the code to GUI
GUI Application example  GUI Application example
Serializing GUI Components Across Network - tutorial
Serializing GUI Components Across Network 2001-03-14 The Java Specialists' Newsletter [Issue 013a] - Serializing GUI Components Across Network Author... to as many people as you know who might be interested in Java. Serializing GUI
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
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
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
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 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 Java JSP application  GUI Java JSP application
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
GUI-Model Rainfall program
. A complete, running, GUI program is built automatically, and it's only...; Following screen shot shows the running application.     GUI class... Java NotesGUI-Model Rainfall program   This is an example
GUI Structural Patterns
Java NotesGUI Structural Patterns Structuring the program - Separating the Model In all ways of structuring a GUI program, there is one vitally important... This is the application of stepwise refinement to GUIs. Parts of the GUI
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
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
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
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
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
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-based Applications
GUI-based Applications      ... application. You need to define a subclass of Frame to create a window for your application. The Frame consists of a Window with a title, menubar, and border
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
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
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
Gui plz help
Gui plz help   Create a Java application that would allow a person to practice math (either addition, subtraction, multiplication or division... far. so basically what i did is i used the java palletes to make a application
Application Server
Application Server       An application server is an application program that accepts connections in order to service requests, by sending back responses. An application server   can
Fill-in: Rainfall GUI
Java NotesFill-in: Rainfall GUI Name ______________________________ (5... like someplace on this page. (15 points) Fill in the blanks in this program... 79 80 81 82 83 84 // RainfallGUI2.java - Provides a GUI interface
Convert the code to GUI ??
Convert the code to GUI ??  hi >> can anyone help me to conver this code to GUI ?? /** * @(#)RegistorClass.java * *. * @author...! ***"); System.out.println("*** Please enter your program one instruction
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: Basic GUI
Java NotesBasic GUI Next - Big Blob This first example just shows what... program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // structure/CalcV1.java // Fred Swartz - December 2004 // GUI
Regarding GUI Applications
GUI Applications  How to create a save and open jmenu item in java desktop application.   Here is a simple JMenuItem example in java swing through which you can perform open and save operations on File. import
Summary - Basic GUI Elements
Java: Summary - Basic GUI Elements In this tutorial we will learn about Basic GUI elements in Java program. Following table summarizes the variable... JFrame.EXIT_ON_CLOSE to terminate program when close box clicked. w.setResizable
Convert the code to GUI
Convert the code to GUI   can any one convert My code to GUI code... to Simpletron! ***"); System.out.println("*** Please enter your program one... to stop entering your program. ***"); System.out.println
Convert the code to GUI
GUI example for beginners  GUI example for beginners  sory... program one instruction ***"); System.out.println("*** (or data word...("*** Type -99999 to stop entering your program. ***"); System.out.println
GUI Interface - Java Beginners
GUI Interface  Respected sir, please send me the codimg of basic calculator,functionality must be include additon ,subtraction,division... calculator program."); class CalcGUI extends JFrame { private final Font BIGGER
(Displaying a calendar in GUI
(Displaying a calendar in GUI  (Displaying a calendar) Write a program that displays the calendar for the current month, as Use labels, and set texts on the labels to display the calendar."The Calendar and GregorianCalendar
program
program  write a javascript program to create a application form with validation
Rainfall GUI Questions
Java NotesRainfall GUI Questions Name ______________________________ This is part of the code to implement the GUI that was used with the Rainfall program. The problem is that there is no button to calculate the average. Add
Regarding GUI Applications
jmenu item in java desktop application  How to create a save and open jmenu item in java desktop application.   Here is a simple JMenuItem example in java swing through which you can perform open and save operations
Regarding GUI Applications
save and open jmenu item  How to create a save and open jmenu item in java desktop application.   Here is a simple JMenuItem example in java swing through which you can perform open and save operations on File

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.