Share on Google+Share on Google+

mahamat ali
JFrame
1 Answer(s)      5 years and 8 months ago
Posted in : Java Beginners

write an application with a JFrame that five labels describing reasons that a customer might not buy your product(for example "Too expensive") every time the user clicks a Jbutton, remove one of the negative reasons.

Ads

View Answers

August 24, 2011 at 5:41 PM


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

public class JFrameExample extends JFrame implements ActionListener {   

    JTextField text = new JTextField(15);
    JButton b = new JButton("Click");
    private int numClicks = 0;
    JLabel lab=new JLabel("Reasons that a customer might not buy item...");
    JLabel lab1=new JLabel("Too small");
    JLabel lab2=new JLabel("Too large");
    JLabel lab3=new JLabel("Quality is not so good");
    JLabel lab4=new JLabel("No warranty");
    JLabel lab5=new JLabel("Too expensive");
    public static void main(String[] args){
        JFrame myWindow = new JFrameExample("Reasons Not to purchase");
        myWindow.setSize(500,300);
        myWindow.setVisible(true);
    }
    public JFrameExample(String title){
        super(title);
        setLayout(null);
        lab.setBounds(10,10,300,20);
        b.setBounds(320,10,80,20);
        lab1.setBounds(100,40,100,20);
        lab2.setBounds(100,70,100,20);
        lab3.setBounds(100,100,150,20);
        lab4.setBounds(100,130,100,20);
        lab5.setBounds(100,160,100,20);

        add(b);
        add(lab);
        add(lab1);
        add(lab2);
        add(lab3);
        add(lab4);
        add(lab5);
        b.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
    numClicks++;
        if(numClicks == 1){
            lab1.setVisible(false);
            lab2.setBounds(100,40,100,20);
            lab3.setBounds(100,70,100,20);
            lab4.setBounds(100,100,150,20);
            lab5.setBounds(100,130,100,20);
        }
        if(numClicks == 2){
            lab2.setVisible(false);
            lab3.setBounds(100,40,100,20);
            lab4.setBounds(100,70,150,20);
            lab5.setBounds(100,100,100,20);
        }
        if(numClicks == 3){
        lab3.setVisible(false);
        lab4.setBounds(100,40,150,20);
        lab5.setBounds(100,70,100,20);
        }
        if(numClicks == 4){
        lab4.setVisible(false);
        lab5.setBounds(100,40,100,20);
        }
        if(numClicks == 5) {
        lab5.setVisible(false);
        }
    }
}









Related Tutorials/Questions & Answers:
JFrame
JFrame  write an application with a JFrame that five labels describing reasons that a customer might not buy your product(for example "Too expensive") every time the user clicks a Jbutton, remove one of the negative reasons
jframe
jframe  Create a JFrame for the Summervale Resort. Allow the user to view the information about different rooms available, dining options and activities offered. Include at least two options in each menu and display appropriate
Advertisements
JFrame
Jframe. How can i do it. Please help me to do it. Or what else can i have
Refresh JFrame
Refresh JFrame  How to refersh a JFrame and its componets
Hiding a JFrame
javax.swing.*; import java.awt.event.*; class PassData extends JFrame { JTextField... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
Hiding a JFrame
javax.swing.*; import java.awt.event.*; class PassData extends JFrame { JTextField... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
how to reset JFrame
how to reset JFrame  how to reset JFrame
refresh checkbox jframe
refresh checkbox jframe  How to refresh checkbox button in JFrame
jframe background color not showing
jframe background color not showing  jframe background color is not showing. please suggest.   Just add the background color to JPanel and then add it to JFrame. For example .. JFrame myFrame = new JFrame(); JPanel
jumping frame jFrame to jInternalframe
jumping frame jFrame to jInternalframe  Afternoon sir, I want to ask... and sub menu(employee). in Form Login(jFrame) have username(textfield1) and password(passwordfield1), in Menu(jframe) have Menu employee(jMenu),creaby(jlabel1
Removing the Title Bar of a JFrame
Removing the Title Bar of a JFrame  How to remove the Title Bar of a JFrame in Swing Application?   Please check the tutorial Removing the Title Bar of a Frame for the source code and example description. Thanks
JFRAME - Java Beginners
javax.swing.*; import java.awt.event.*; public class MenuExample extends JFrame
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to move label in jframe in java?
how to move label in jframe in java?  please any one can give me code for moving a java label in Jframe
JFrame Button click to start play
JFrame Button click to start play  i made a game and and i add a button in new jframe and i want when i click it it start to play...can anyone help me
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir i am doing a project so i am working in netbeans i have to print a JFrame it contains Labels and few textboxfields so i want to take the whole JFrame contents for printing so would you
setbackground image to JFrame - Java Beginners
setbackground image to JFrame   how to setbackground image to JFrame... TransparentBackgroundImage { public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener( new WindowAdapter() { public
insert image in JFrame - Development process
); } static public void main(String args[]) throws Exception { JFrame frame = new JFrame("Display image"); Panel panel = new ShowImage
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... but i go through the link that you have specified http://www.roseindia.net/java... PrintExample extends JFrame implements ActionListener { public static void main
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... but i go through the link that you have specified http://www.roseindia.net/java... PrintExample extends JFrame implements ActionListener { public static void main
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir thanks a lot for your reply... but i go through the link that you have specified http://www.roseindia.net/java... this public class PrintExample extends JFrame implements ActionListener { public
display multiple images from postgres database in jframe
display multiple images from postgres database in jframe  i just want to display multiple images on jframe by firing a query on postgres database
Java Image On JFrame Title
How to set Image On JFrame In this section, you will learn how to set an image on JFrame title using Java program. For this, we have created an object of JFrame class. Then, we have used Toolkit.getDefaultToolkit().getImage
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads