please give me a java program for the following question

Ads
 

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);
}
}

Ads









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 displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
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 prompts the user to enter the number of students and each studentā??s name and score, and finally displays the name of the students
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  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...) The formula for the conversion is: inches = 2.54 * centimeters Write a program
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... a program that prompts the user to enter a weight in pounds and height in inches
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 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 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
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 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
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 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
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 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...() > 1) System.out.println("It is not character. Please enter
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 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
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 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 2 1 1 3 4 3 1 1 4 7 7 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 1 1 3 3 1 1 4 6 4 1

Ads