JPasswordField password = new JPasswordField(); String passText = new String(password.getPassword()); // get ค่า
package com.java.myapp; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JPasswordField; public class MyForm extends JFrame { /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { MyForm frame = new MyForm(); frame.setVisible(true); } }); } /** * Create the frame. */ public MyForm() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 362, 249); setTitle("ThaiCreate.Com Java GUI Tutorial"); getContentPane().setLayout(null); // Password Field final JPasswordField password = new JPasswordField(); password.setBounds(108, 26, 139, 20); getContentPane().add(password); // Label final JLabel lbl = new JLabel("Result"); lbl.setBounds(103, 120, 144, 14); getContentPane().add(lbl); // Button JButton btn1 = new JButton("Button 1"); btn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String passText = new String(password.getPassword()); lbl.setText("Password = "+ passText); } }); btn1.setBounds(128, 72, 99, 23); getContentPane().add(btn1); } }
String passText = new String(password.getPassword())
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท