please give me a java program for the following question

please give me a java program for the following question

Write a java program that displays multiple frames : Step 1: Design a frame with three buttons: ?Fruit?, ?Bird? and ?Animal? Step 2: On clicking ?Fruit? button display another frame that shows a picture of a fruit of your interest. On clicking ?Bird? button display another frame that shows a picture of a bird of your interest. On clicking ?Animal? button display another frame that shows a picture of a animal of your interest. Have icons for your buttons

View Answers

September 17, 2012 at 1:40 PM

Here is an example that displays three buttons and display another frame when they are clicked.

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

public class MultipleFrame{

public static void main(String[] args){
JFrame f = new JFrame("");
f.setLayout(new FlowLayout());
JButton button1=new JButton("Fruit");
Icon icon1 = new ImageIcon("c:/fruit.png");
JButton button2=new JButton("Bird");
Icon icon2 = new ImageIcon("c:/bird.png");
JButton button3=new JButton("Animal");
Icon icon3 = new ImageIcon("c:/animal.png");
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Mango");
 Icon icon = new ImageIcon("c:/mango.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Peacock");
 Icon icon = new ImageIcon("c:/peacock.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(500,300);
 }
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Giraffe");
 Icon icon = new ImageIcon("c:/giraffe.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
f.add(button1);
f.add(button2);
f.add(button3);

f.setSize(300,150);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

September 17, 2012 at 5:14 PM

In the previous code, we forget to add an icon to button. So we are sending the updated code.

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

public class MultipleFrame{

public static void main(String[] args){
JFrame f = new JFrame("");
f.setLayout(new FlowLayout());
JButton button1=new JButton("Fruit");
Icon icon1 = new ImageIcon("c:/fruit.png");
button1.setIcon(icon1);
JButton button2=new JButton("Bird");
Icon icon2 = new ImageIcon("c:/bird.png");
button2.setIcon(icon2);
JButton button3=new JButton("Animal");
Icon icon3 = new ImageIcon("c:/animal.png");
button3.setIcon(icon3);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Mango");
 Icon icon = new ImageIcon("c:/mango.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Peacock");
 Icon icon = new ImageIcon("c:/peacock.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(500,300);
 }
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Giraffe");
 Icon icon = new ImageIcon("c:/giraffe.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
f.add(button1);
f.add(button2);
f.add(button3);

f.setSize(300,150);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}









Related Tutorials/Questions & Answers:
please give me a java program for the following question
please give me a java program for the following question  Write a java program that displays multiple frames : Step 1: Design a frame with three buttons: ?Fruit?, ?Bird? and ?Animal? Step 2: On clicking ?Fruit? button
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that prompts the user to enter the number of students and each studentā??s name and score, and finally displays the name of the students
Advertisements
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Suppose that the tuition for a university is RM10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a function called ChangeToNext that take in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a class that contains the following two methods: /* converts from inches... for the conversion is: inches = 2.54 * centimeters Write a program that invokes
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Body Mass Index(BMI) is a measure of health on weight. It can be calculated by taking... (adsbygoogle = window.adsbygoogle || []).push({}); Write a program that prompts
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  example java coding that reads in the radius and length of cylinder and computes volume. formula: Area = radius * radius * PI Volume = area * length
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  Write a java program that reads the following information and prints a payroll... withholding rate(e.g: 9%) The program should calculates the gross pay, total
hi... pls give me the example of java coding for following question
hi... pls give me the example of java coding for following question   Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest
why and where we use setter and getter methods in java, please give me one example program.....
why and where we use setter and getter methods in java, please give me one example program.....  why and where we use setter and getter methods in java, please give me one example program
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character..., http://www.roseindia.net/java
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named... John von Neumann Donald Knuth Charles Babbage Grace Hopper your program should...(); } } } ------------------------------- read for more information, http://www.roseindia.net/java/beginners/read
Please give me coding for this..
Please give me coding for this..  Write an application that inputs... spaces each.For Example.if the user types the number 42339,the program should print... happens when you execute the program and type a number with more than five digits
hello sir, please give me answer - Java Beginners
hello sir, please give me answer  Write a program in Java that calculates the sum of digits of an input number, prints... ways in java? so , sir please tell me full solution of this program   Here is your complete
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books... Vidya  Hi Friend, Try the following code: import java.util.
please help me for this program - Java Beginners
please help me for this program   Write a program that asks the user for a starting value and an ending value and then writes all the integers... 11 12 13 14   Hi Friend, Try the following code: import
please help me in a java program !! - Java Beginners
please help me in a java program !!  the porgram should use...://en.wikipedia.org/wiki/Kosaraju_algorithm) there are 4 classes in my program : Vertex... and run the program" i still need to modify the method kosaraju in the class Graph
Pleae help me to give logic and code for this program - Java Beginners
Pleae help me to give logic and code for this program  Write a function that given the string ?original? create a new string ?dramatic? that has two...://www.roseindia.net/java/beginners/StringReverseUsingStringUtils.shtml
Please explain me the flow of this program..
Please explain me the flow of this program..  // Substring replacement. class StringReplace { public static void main(String args[]) { String org = "This is a test. This is, too."; String search
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
please explain me the flow of this program
please explain me the flow of this program  class Bticket extends Thread { Object train,comp; Bticket(Object train,Object comp){ this.train=train; this.comp=comp; } public void run(){ synchronized
please give me an example about shopping cart using spring and hibernate
please give me an example about shopping cart using spring and hibernate  who can give me an ex about shoppingcart using spring and hibernate intergration ? thanks alot
java program.. the question is scary ...please help - Java Beginners
java program.. the question is scary ...please help  Modify the Lexer..., etc. 4. Print each token with line number READLINE: program { int i int j program left: 0 right: 6 line: 1 { left: 8 right: 8: line: 1 int
please help me to solve this question about array
please help me to solve this question about array  write a program... character. The program should ignore the case of that character (uppercase or lowercase.... Please enter character"); else { ch = brr.charAt(0
Hi Every One , please give me some idia to opning audio File . please Help ..
Hi Every One , please give me some idia to opning audio File . please Help ..  hi Dear Friend , please give me a program to opening audio file... me .please Help
please help me in coding this given program
please help me in coding this given program  consider the below... are the prime numbers in ascending order write a program to find the nth term in this series. (i m unable to code this program..please provide solution
please help me in coding this given program
please help me in coding this given program  consider the below... are the prime numbers in ascending order write a program to find the nth term in this series. (i m unable to code this program..please provide solution
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  Q 1) In a class first day 25 students are joined. After two days that total students will increased to 60. We can develop a program by using ArrayList concept
please tell me the flow of execution of this program
please tell me the flow of execution of this program  class Test{ int x; Test(int x){ this.x=x; } static void access(){ System.out.println("x= "+x); }} class Static{ public static void main(String ar[]){ Test obj=new Test(55
Give me some java Forum like Rose India.net
Give me some java Forum like Rose India.net  Friends... Please suggest some forum like RoseIndia.net where we can ask question like here. Thanks
Give me some java Forum like Rose India.net
Give me some java Forum like Rose India.net  Friends... Please suggest some forum like RoseIndia.net where we can ask question like here. Thanks
please eslain me the flow of execution of this program
please eslain me the flow of execution of this program  class Producer extends Thread { StringBuffer sb; boolean dataprodover = false; Producer(){ sb = new StringBuffer(); } public void run(){ for(int i=1;i<=10;i++){ try
need a java program for the following
need a java program for the following  Write a java program with three horizontal sliders. Name the sliders, the first one as red, the second one as green and the third one as blue. You design the program such that on varying
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.  HERES TEH QUESTION - I AM MISSING SOME..., ADDRESS AND ADMISSIONS CLASS PLEASE HELP!!! Write a Java program which
please help me to answers this question about C++.....huuhuhuhu
please help me to answers this question about C++.....huuhuhuhu  1) Write a full program for the bubble sort algorithm. User is required to enter... program fragments: a. Give an analysis of the running time (Big-Oh) b
please help me to answers this question about C++.....huuhuhuhu
please help me to answers this question about C++.....huuhuhuhu  1) Write a full program for the bubble sort algorithm. User is required to enter... program fragments: a. Give an analysis of the running time (Big-Oh) b
Help me please!!! - Java Beginners
Help me please!!!  im badly needing the complete code for this project in java!!! can you please help me???!!! it is about 1-dimensional array... the answers 8Hours from now!!! Kindly help me!! please!!please!!! NOTE
core java code for following program
core java code for following program  We are hosting the Olympic games. Write a program that will track all the details of this hosting.... The following are the guidelines while writing this program Only command line based
please help me - Java Beginners
please help me   I have some error in this programe //write acomputer programe using java to generate following series : //output: //1,2,3,0,-2,7,-4..... class Series1HW { public static void main(String args

Ads