Results 1 to 3 of 3
Thread: [SOLVED] couldn't find a way
- 12-15-2008, 10:02 PM #1
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
[SOLVED] couldn't find a way
Firstly, I am sorry about that I asked same question in GUI and couldn't get a solution.
I try to write code for a telephone directory program. I wrote code for main fuctions(search-save-delete).here is code sample
I did not add code of functions(save-delete-search). Problem is about action button. It does not work. Also I need some Jtextfield on "FirstPanel" and I would like to give the coordiante for these Jtextfield. I want to take string value on texfield by using action button. Could you please tell me how to do these 3 things. I really need a solution. Thanks in advance.Java Code:import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; public class Tel_Dir extends JFrame implements ActionListener { public static void main(String[] args) { new Tel_Dir(); } JPanel mainpanel; CardLayout mainLayout; public Tel_Dir() { createGUI(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setLocationRelativeTo(null); setAlwaysOnTop(false); setVisible(true); } private void createGUI() { mainLayout = new CardLayout(); mainpanel = new JPanel(); mainpanel.setLayout(mainLayout); mainpanel.add(new FirstPanel(null), "part1_layout"); mainpanel.add(new SecondPanel(), "part2_layout"); mainpanel.add(new ThirdPanel(), "part3_layout"); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(new SidePanel(this), BorderLayout.WEST); panel.add(mainpanel, BorderLayout.CENTER); getContentPane().add(panel); } public void actionPerformed(ActionEvent evn) { String cmd = evn.getActionCommand(); if ("button1".equals(cmd)) { mainLayout.show(mainpanel, "part1_layout"); } else if ("button2".equals(cmd)) { mainLayout.show(mainpanel, "part2_layout"); } else if ("button3".equals(cmd)) { mainLayout.show(mainpanel, "part3_layout"); } } public void actionPerformed2(ActionEvent e) { String cmd2 = e.getActionCommand(); if ("button4".equals(cmd2)) { System.out.println("pushed"); } } private class SidePanel extends JPanel { public SidePanel(ActionListener listener) { createGUI(listener); } private void createGUI(ActionListener listener) { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(Box.createVerticalStrut(4)); JButton quickbutton = new JButton("QUİCK SEARCH "); quickbutton.addActionListener(listener); quickbutton.setActionCommand("button1"); add(quickbutton); add(Box.createVerticalStrut(8)); JButton savedelbutton = new JButton("SAVE OR DELETE "); savedelbutton.addActionListener(listener); savedelbutton.setActionCommand("button2"); add(savedelbutton); add(Box.createVerticalStrut(8)); JButton standardbutton = new JButton("STANDARD SEARCH"); standardbutton.addActionListener(listener); standardbutton.setActionCommand("button3"); add(standardbutton); add(Box.createVerticalStrut(8)); } } private class FirstPanel extends JPanel { public FirstPanel(ActionListener listener2) { createGUI(listener2); } private void createGUI(ActionListener listener2) { setLayout(null); JButton actionbutton1 = new JButton("action"); JTextField tex = new JTextField(); actionbutton1.addActionListener(listener2); actionbutton1.setActionCommand("button4"); actionbutton1.setBounds(30, 30, 100, 30); add(actionbutton1); tex.setBounds(30, 70, 100, 30); add(tex); } } private class SecondPanel extends JPanel { public SecondPanel() { createGUI(); } private void createGUI() { setLayout(new BorderLayout()); add(new JLabel("Under Construction", JLabel.CENTER)); } } private class ThirdPanel extends JPanel { public ThirdPanel() { createGUI(); } private void createGUI() { setLayout(new BorderLayout()); add(new JLabel("Under Construction", JLabel.CENTER)); } } } }
Kind regards,
Salih Ozan IRBIK.Last edited by tOpach; 12-16-2008 at 01:33 PM. Reason: changed the code
A stitch in time saves nine:D
- 12-16-2008, 01:14 PM #2
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
Could anyone help me about my program!
I wish to use "action" button(ıt does not work now) to take data form textfield .Please.Last edited by tOpach; 12-16-2008 at 01:33 PM.
A stitch in time saves nine:D
- 12-17-2008, 12:00 AM #3
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
can't find tamplate.tld anywhere
By amu in forum Advanced JavaReplies: 1Last Post: 10-15-2008, 02:15 PM -
cannot find imports..
By little_polarbear in forum New To JavaReplies: 4Last Post: 08-25-2008, 03:57 AM -
PLEASE!!!help me to find mistake
By sasha20 in forum New To JavaReplies: 1Last Post: 01-11-2008, 10:50 AM -
Where to find wsimport
By javaplus in forum Web FrameworksReplies: 1Last Post: 11-26-2007, 09:59 AM -
cannot find a JVM installed
By tommy in forum New To JavaReplies: 2Last Post: 07-29-2007, 08:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks