From 7f21e89a0afec0edc396ea67d60a20674af4fd77 Mon Sep 17 00:00:00 2001 From: tonyhcj Date: Wed, 29 Jul 2026 15:00:44 -0300 Subject: [PATCH] fix: salvando nome e porta --- pitiupi/src/pitiupi/GUI/Login.java | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pitiupi/src/pitiupi/GUI/Login.java b/pitiupi/src/pitiupi/GUI/Login.java index 3b3765e..2fde02c 100644 --- a/pitiupi/src/pitiupi/GUI/Login.java +++ b/pitiupi/src/pitiupi/GUI/Login.java @@ -1,8 +1,3 @@ -/* - * 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 pitiupi.GUI; import java.awt.BorderLayout; @@ -11,6 +6,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; +import java.util.prefs.Preferences; import javax.swing.JButton; import javax.swing.JDialog; @@ -26,6 +22,10 @@ import javax.swing.JTextField; */ public final class Login extends JDialog { + private static final Preferences prefs = Preferences.userNodeForPackage(Login.class); + private static final String PREF_NOME = "lastUserName"; + private static final String PREF_PORTA = "lastPort"; + JLabel nameLabel = new JLabel("Name: "); JLabel portLabel = new JLabel("Port: "); @@ -44,8 +44,12 @@ public final class Login extends JDialog { public void initComponents() { this.setTitle("Login"); - portField.setModel(new javax.swing.SpinnerNumberModel(8000, 8000, 9000, 1)); - nameField.setText(System.getProperty("user.name")); + + String nomeSalvo = prefs.get(PREF_NOME, System.getProperty("user.name")); + int portaSalva = prefs.getInt(PREF_PORTA, 8000); + + portField.setModel(new javax.swing.SpinnerNumberModel(portaSalva, 8000, 9000, 1)); + nameField.setText(nomeSalvo); JPanel topPanel = new JPanel(new GridBagLayout()); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); @@ -83,17 +87,19 @@ public final class Login extends JDialog { this.add(topPanel); this.add(buttonPanel, BorderLayout.SOUTH); - okButton.addActionListener((ActionEvent e) -> { try { portField.commitEdit(); } catch (java.text.ParseException ex) { return; } + + prefs.put(PREF_NOME, nameField.getText()); + prefs.putInt(PREF_PORTA, (Integer) portField.getValue()); + Login.this.setVisible(false); }); - cancelButton.addActionListener((ActionEvent e) -> { System.exit(0); });