Dunque..forse ora ho capito la logica. Però ancora non funziona. Sicuramente colpa mia e non tua.
Posto di nuovo il codice per farti capire cosa ho combinato:
Questa è la classe interfaccia:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package md5converter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.scene.layout.Border;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author Nicola
*/
public class GUI extends JFrame {
private JTextField inputField;
private JTextField outputField;
private void encryptString() {
String input = inputField.getText();
String output = Converter.encrypt(input);
outputField.setText(output);
}
public GUI() {
super();
JLabel stringToConvert = new JLabel("String to convert");
JTextField inputString = new JTextField(10);
JLabel encryptedString = new JLabel("Encrypted String");
JTextField outputString = new JTextField(10);
JButton encrypt = new JButton("Encrypt");
JButton reset = new JButton("Reset");
encrypt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Converter.encrypt(outputField.getText());
}
}
);
JPanel mainPanelInput = new JPanel();
mainPanelInput.setLayout(new FlowLayout());
mainPanelInput.add(stringToConvert);
mainPanelInput.add(inputString);
JPanel mainPanelOutput = new JPanel();
mainPanelOutput.setLayout(new FlowLayout());
mainPanelOutput.add(encryptedString);
mainPanelOutput.add(outputString);
JPanel buttonPanel = new JPanel();
buttonPanel.add(encrypt);
buttonPanel.add(reset);
JPanel northPanel = new JPanel();
northPanel.setLayout(new GridLayout(3, 1, 0, 20));
northPanel.add(mainPanelInput);
northPanel.add(mainPanelOutput);
northPanel.add(buttonPanel);
this.add(northPanel, BorderLayout.NORTH);
}
public void setDefault() {
setTitle("MD5 Encrypter");
setSize(500, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
}
Ho messo tutto perchè magari manca una cavolata..però penso che la seconda metà non serva a risolvere il problema.
Ti posto anche l'errore che riporta:
run:
Inserisci una stringa da convertire :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at md5converter.GUI$1.actionPerformed(GUI.java:51)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
GUI:java51 sarebbe questa riga: Converter.encrypt(outputField.getText());
Dove sbaglio?
ps. ho provato con outputString.getText()) invece che outputField e non da errori..però non visualizza comunque niente dove dovrebbe uscire la stringa criptata