how to show variable's value in pop up dialog with java swing


MikeT
26/4/2016 6:52 am
HOME ยป Web Development

I am a beginner in programming. I was messing around with java swing and tried to make a silly app. This is my code. It's not showing any errors, but it's not working. When the dialog pops up, the variable's value doesn't show on the dialog. The logic i used is right, because when i run it in the compiler without the GUI stuff, it works perfectly. If anyone could tell what am i doing wrong in here, it would be really helpful.

this is my code for the calculations.

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;

public class swingApp extends JFrame{
    JLabel label;
    JButton button;
    public JLabel label2;
    JTextField textField = new JTextField("enter you nicknamae");
    String username=textField.getText();
    public int geniusMeter;
    public int sum=0;
    public String sumAsString;
    public void swingAppLogic(String name){
        char[] letters = username.toCharArray();
        char []
alphabet={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        int []
measure={7,3,1,13,8,26,15,18,2,5,22,20,16,9,5,11,23,12,25,6,4,21,24,14,17,10};

        for(int count=0;count<letters.length;count++){
            for (int count1=0;count1<alphabet.length;count1++){
                if (letters[count]==alphabet[count1]){
                    geniusMeter=measure[count1];
                    sum=sum+geniusMeter;
                    break;
                }
            }
        }
        sumAsString = Integer.toString(sum);

    }

    public swingApp(){
        super("Genius Calculator");
        setLayout(new FlowLayout());
        label = new JLabel("Wanna know how genius you are?"); 
        label2 = new JLabel(" ");
        button = new JButton("press enter and then click me to know
the results");
        handlerClass handler = new handlerClass();
        button.addActionListener(handler);
        add(label);
        add(label2);
        add(button);
        add(textField);
    }
    public class handlerClass implements ActionListener{
        public void actionPerformed(ActionEvent event){
            JOptionPane.showMessageDialog (null, sumAsString, "Title",
JOptionPane.INFORMATION_MESSAGE);

        }
    }
}

and this is my main method

import javax.swing.JFrame;

public class swingAppTester{
    public static void main (String [] args){
        swingApp object=new swingApp();

        object.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        object.setSize(500,400);
        object.setVisible(true);
    }
}

Related to : how to show variable's value in pop up dialog with java swing
how to show variable's value in pop up dialog with java swing
26/4/2016 6:52 am by MikeT in Web Development

I am a beginner in programming. I was messing around with java swing and tried to make a silly app. This is my code. It's not showing any errors, but it's not working. When the dialog pops up, the variable's value doesn't show on the dialog. The logic i used is right, because when i run it in the


Show dialog when Swing exception is thrown
by enginecrew in Web Development

I have a Java application that uses swing. I have found a way to catch all uncaught exception in an application (see below). I would like to log a message, show a dialog with a message for the user and kill the application. The problem is, what I'm trying to catch are some swing exceptions. Tryin


java swing error dialog box
21/12/2014 2:20 pm by gitano in Web Development

i have a dialog box to be shown but it is giving compilation errors. The compilation errors are given in the last part.

import javax.swing.*;
class SwingDemo {
SwingDemo() {

JFrame jfrm = new JFrame("A Simple Swing Application");

jfrm.setSize(275, 100);

jfrm.setDefaultCloseOpe
Java Swing option dialog modifications
by Hubb1e in Web Development

I use the code below to create an option dialog.
How would i add space between the "Confirm" and "Cancel" button.
I want to remove the question mark, but i can't center the text when i change the dialog to a JOptionPane.PLAIN_MESSAGE.


String[] options = { "Confirm", "Canc
Java Swing: JInternalFrame: need a dialog popup
by BiaachMonkie in Web Development

I have a JInternalFrame window that needs to popup a modal dialog box when a JButton is pressed. At first, I tried using JDialog, but I found that JDialog constructor needs:


JFrame
boolean modal

I tried passing JInternalFrame to it, but the type didn't match.


Sho


Java Swing: positioning dialog on top of existing window
by dreampunchboy in Web Development

Can someone show simple Java Swing code/web resource that will position the popup dialog center-aligned on top of an existing JFrame window when the JFrame's button clicked?


How to unit test with Java Swing JOptionPane Confirm Dialog
by Edwin41 in Web Development

I have a java swing application which expects the users to choose YES or NO from JOptionPane.showConfirmDialog


Since the JOptionPane stops the thread and is waiting for user input, my code is not automatically testable.


Is there anywa


Java Swing: Controlling focus with textfield and autocompletion dialog/menu
20/12/2014 4:40 pm by piratus in Web Development

I have a JTextField that I'm trying to add an autocompletion menu to. But I'm having issues with how I should handle the focus.

Here's a SSCCE

package test;

import java.awt.Point;

import javax.swing.JDialog;
import javax.swi
Java swing doesn't show changes to source
by Edwin41 in Web Development

I'm using Java Swing graphical editor with netbeans to make my project...but using it brings some limitations like I can't add to a jpanel an image,using java swing options. So i'll need to code it, implementing a new jPanel.


My problem is that the code generated by the java swing gr


How to convert java code ARRAY from basic println to swing dialog prompt
by FrankSaucedo in Web Development

//Date: 3/16/2010import javax.swing.*;class PizzaChoice { public static void main(String[] args) throws Exception {char[] whatSize = { 'S', 'M', 'L', 'X'};char size;double[] sizePrice = {6.99, 8.99, 12.50, 15.00};int s;System.out.println("What size do you want?");size = C


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .