i'm making a program which needs the access to the text in JTextField......
i just want to know how to do it....
the first thing that program do is that it gives the current date.....
button listener classCode:package date.update; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionListener; import java.util.Date; import javax.swing.*; public class DateUpdate { public static void main(String[] args) { // TODO code application logic here JFrame f = new JFrame("DATE-UPDATE"); f.setBackground(Color.LIGHT_GRAY); JTextField TF = new JTextField("hello",50); JTextField TF1 = new JTextField(); InputReader IR = new InputReader(); JTable T = new JTable(); String[] headers = {"MONDAY","TUESDAY"/*,"WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"*/}; Object[][] data = {{"DS","M3"},{"M3","DS"}}; T = new JTable(data,headers); JScrollPane scrollPane = new JScrollPane(T); T.setFillsViewportHeight(true); JButton B = new JButton("DATE"); JButtonListener JBL = new JButtonListener(TF1); B.addActionListener(JBL); f.getContentPane().add(B, BorderLayout.EAST); f.getContentPane().add(TF,BorderLayout.NORTH); f.getContentPane().add(TF1,BorderLayout.PAGE_END); f.add(scrollPane); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true);
Code:public class JButtonListener implements ActionListener{ private JTextField tf1 = new JTextField(); JButtonListener() { } JButtonListener(final JTextField tf) { tf1 = tf; } public void actionPerformed(final ActionEvent AE) { final Date date = new Date(); tf1.setText(""+date); } }
so i want to access the text of TF1 i.e the current date.....




Reply With Quote