Visualizzazione dei risultati da 1 a 4 su 4

Discussione: gettext() java

  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2011
    Messaggi
    197

    gettext() java

    volevo fare un programma che prendesse cio che si scriveva in un jtextfield e poi rimettesse cio che elaboro ho gia scritto questo ma non va sapreste aiutarmi il codice e qui:
    codice:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Calcolatrice {
    	static JFrame window;
    	public static void main(String[] args){
    		// schedule this for the event dispatch thread (edt)
    		SwingUtilities.invokeLater(new Runnable(){
    			public void run(){
    				displayJFrame();
    			}
    		});
    	}
    	static void displayJFrame(){
    		window = new JFrame("Test");	
    		window.getContentPane().setLayout(new FlowLayout());
    		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		window.setResizable(false);
    		window.pack();
    		window.setVisible(true);
    		JTextField Textarea = new JTextField(16);
    		Textarea.setPreferredSize(new Dimension(100,20));
    		window.add(Textarea);
    		JButton showDialogButton = new JButton("INVIO");
    		window.add(showDialogButton);
    		showDialogButton.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				String data = JTextField.getText();
    				System.out.println(data);
    			}
    		});
    		JButton p = new JButton("HELP");
    		window.add(p);
    		p.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				// display/center the jdialog when the button is pressed
    				JDialog d = new JDialog(window, "Hello", true);
    				d.setLocationRelativeTo(window);
    				d.setVisible(true);
    			}
    		});
    	}
    }
    G181

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2011
    Messaggi
    197
    cercando su internet ho provato questo ma non va cmq sapreste dirmi perche:
    codice:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Calcolatrice {
    	static JFrame window;
    	public static void main(String[] args){
    		// schedule this for the event dispatch thread (edt)
    		SwingUtilities.invokeLater(new Runnable(){
    			public void run(){
    				displayJFrame();
    			}
    		});
    	}
    	static void displayJFrame(){
    		window = new JFrame("Test");	
    		window.getContentPane().setLayout(new FlowLayout());
    		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		window.setResizable(false);
    		window.pack();
    		window.setVisible(true);
    		JTextArea TextArea = new JTextArea();
    		TextArea.setPreferredSize(new Dimension(100,20));
    		window.add(TextArea);
    		JButton showDialogButton = new JButton("INVIO");
    		window.add(showDialogButton);
    		showDialogButton.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				String text1 = TextArea.getText();
    				System.out.println(text1);
    			}
    		});
    		JButton p = new JButton("HELP");
    		window.add(p);
    		p.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				// display/center the jdialog when the button is pressed
    				JDialog d = new JDialog(window, "Hello", true);
    				d.setLocationRelativeTo(window);
    				d.setVisible(true);
    			}
    		});
    	}
    }
    G181

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2011
    Messaggi
    197
    risolto cosi:
    codice:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Calcolatrice extends JFrame implements ActionListener{
        public static void main(String[] argv){
    		//inizialize frame
            Calcolatrice mainApp = new Calcolatrice();
        }
        public Calcolatrice()
        {
    		//set frame
            super("JTextArea Example");
    		setResizable (false);
    		pack();
            setBounds(0, 0, 300, 150);
            getContentPane().setLayout(null);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
    		//add textarea
            textarea = new JTextArea();
            textarea.setBounds(0, 0, 294, 78);
    		//add button
            button1 = new JButton("Copy Text Area to Console Window");
            button1.setBounds(0, 78, 294, 22);
    		//add button
            button2 = new JButton("Copy Text Area to Console Window");
            button2.setBounds(0, 100, 294, 22);
    		//add listener
            button1.addActionListener(this);
    		button2.addActionListener(this);
    		//add frame
            getContentPane().add(textarea);
            getContentPane().add(button1);
    		getContentPane().add(button2);
            setVisible(true);
        }
        //eventi
        public void actionPerformed(ActionEvent e){
            if(e.getSource() == button1){System.out.println(textarea.getText());}
            if(e.getSource() == button2){System.out.println(textarea.getText());}
        }
        JButton   button1;
    	JButton   button2;
        JTextArea textarea;
    }
    G181

  4. #4

    Moderazione

    Tra parentesi, in futuro ricordati che i blocchi di codice vanno inseriti tra tag [code] ... [/code], altrimenti perdono l'indentazione.
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.