Visualizzazione dei risultati da 1 a 3 su 3

Discussione: [Java]Copia

  1. #1

    [Java]Copia

    codice:
    import java.io.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    class SecPan extends JPanel
    {
    	// --------
    	private JButton bEs = new JButton("Esegui...");
    	private JTextField tInit = new JTextField("Valore Iniziale");
    	private JTextField tFin = new JTextField("Valore Finale");
    	private JComboBox cSel = new JComboBox(); // selezione per crittare/decrittare
    	// --------	
    	public SecPan()
    	{		
    		// bEs
    		bEs.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{	
    				if(cSel.getSelectedIndex() == 0){ /* crittazione */
    					Rot13Cript enc = new Rot13Cript();		
    					tFin.setText(enc.encript(tInit.getText()));
    				}else if(cSel.getSelectedIndex() == 1){ /* decrittazione */
    					Rot13Cript dec = new Rot13Cript();		
    					tFin.setText(dec.decript(tInit.getText()));
    				}
    			}
    		});
    		bEs.setToolTipText("Esegue l'operazione assegnata");
    		bEs.setEnabled(true);
    		// tEnc
    		tInit.setFont(new Font("Verdana", Font.BOLD, 12));
    		// tInit
    		tInit.addFocusListener(new FocusListener()
    		{
    			public void focusGained(FocusEvent f)
    			{
    				tInit.setText(" ");
    			}
    			public void focusLost(FocusEvent f)
    			{
    			}
    		});
    		// tFin
    		tFin.setFont(new Font("Verdana", Font.BOLD, 12));
    	
    		// cSel
    		cSel.addItem("Critta");
    		cSel.addItem("Decritta");
    		Font font_sel = new Font("Verdana", Font.BOLD, 12);
    		cSel.setFont(font_sel);
    		cSel.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{	
    				tInit.setText(" ");
    				tFin.setText(" ");
    			}
    		});
    		// Add Component
    		setLayout(new BorderLayout(5,16));
    		add(cSel, BorderLayout.NORTH);
    		add(tInit, BorderLayout.CENTER);
    		add(bEs, BorderLayout.SOUTH);
    		add(tFin, BorderLayout.AFTER_LINE_ENDS);
    	}	
    	public String getBufferInit()
    	{
    		return tInit.getText();
    	}
    	public String getBufferFin()
    	{
    		return tFin.getText();
    	}
    	public void setBufferInit(String arg1)
    	{
    		tInit.setText(arg1);
    	}
    	public void setBufferFin(String arg1)
    	{
    		tFin.setText(arg1);
    	}
    } 
    
    class BufPan extends JPanel
    {
    	private JButton bCopy = new JButton("Copia"); // il bottone x copiare
    	private JButton bPast = new JButton("Incolla");// il bottone x incollare
    	
    	public BufPan()
    	{
    		// bCopy
    		bCopy.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				SecPan pan = new SecPan();
    				String buf = new String();
    				buf = null;
    				buf = pan.getBufferInit();
    				System.out.println(buf);
    				pan.setBufferFin(buf);
    				
    			}
    		});
    		
    		// bPast
    		bPast.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{	
    			}
    		});
    		setLayout(new BorderLayout());
    		add(bCopy, BorderLayout.NORTH);
    		add(bPast, BorderLayout.CENTER);
    		bCopy.setToolTipText("In Construzione...");
    		bPast.setToolTipText("In Construzione...");
    	}
    		
    } 
     
    class SecF extends JFrame 
    {
    	public SecF()
    	{
    		// Form
    		setTitle("Security");
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
    		super.setResizable(false);
    		getContentPane().setLayout(new BorderLayout());
    		getContentPane().add(new SecPan(), BorderLayout.NORTH);
    		getContentPane().add(new BufPan(), BorderLayout.SOUTH);
    		setLocation(600, 400);
    		pack();
    	}		
    }
    
    class Security
    {
    	public static void main(String[] args)
    	{
    		SecF princ = new SecF();
    		princ.setVisible(true);	
    	}
    }
    cliccando su copia pero nn mi setta il tFin.............why???
    La situaz è cosi cmq:
    i getBufferxx() vanno ma mi prendono solo Valore Iniziale o Valore Finale
    setBufferXX() no



    Help me


    Tnk 1000 ad ogni aiuto

    P.S: come nomenclature sono ok le var e i metodi?
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  2. #2
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  3. #3
    Utente di HTML.it L'avatar di anx721
    Registrato dal
    Apr 2003
    Messaggi
    2,352
    Non ho letto attentamente il codice, però mi sembra che qualche problema possa derivare dal fatto che esegui le istruzioni:

    XXX..addActionListener(new ActionListener())

    Creando un nuovo ActionListener, gli eventi prodotti dai bottoni saranno indirizzati verso quel nuovo ActionListener, che non è programmato per gestirli. Generalmente addActionListener() si usa in istruzioni tipo:

    XXX.addActionListener(this)

    in qquesta maniera al JButton viene aggiunto come listener l'oggetto corrente, che puo essere ad esempio il JFrame o il JPanel in cui hai dichiarato il JButton. Quindi in quel Jframe o (JPanel) devi dichiarare il metodo actionPerformed(ActionEvent e), e nel metodo ti ricavi l'elemento che ha prodotto l'evento con : "Object o = e.getSource()" e poi esegui degli 'if' su 'o' per sapere cosa è 'o':

    public void actionPerformed(ActionEvent e)
    {

    .....Object o = e.getSource();

    .....if(o == bCopy)
    .....{
    ........//istruzioni da eseguire quando si clicca su bCopy
    .........return;
    ......}

    ......if(o == bPaste)
    ......{
    .........//istruzioni da eseguire quando si clicca su bPaste
    .........return;
    ......}
    }

    }

    Ciao.

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.