Results 1 to 5 of 5
Thread: disable button in a fuction
- 04-28-2011, 08:17 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
disable button in a fuction
Hello
Im very new java in fact not a java programmer but im modifying a source code which i need
my problem is as follow
i have two java file each consist of their own classes and functions
i have a case in which when application start i disable one of the button then if user click on setting tab the second java files is called i want to reenable button in the first java class file again
sorry if im not very clear
part of code
first file which create ui and buttons and i disable jb1 button here
Java Code:public static void main(final String args[]) { // copy certificate file from jar. final ProxyUIStarter proxyUIStarter = new ProxyUIStarter(); final InputStream is = proxyUIStarter.getClass().getResourceAsStream( "/ProxyCertificate.ser"); proxyUIStarter.copyFile(proxyUIStarter, is); final String currentDir = new File("").getAbsolutePath(); final File file = new File(currentDir + File.separator + "ProxyConfig.dat"); if (!file.exists()) { ProxyUIStarter.showSettings(); } else { final Settings getvalues = new Settings(); getvalues.updateField(); authorize tc = new authorize(); tc.authorizeing(); } final String cerfile = currentDir + File.separator + "ProxyCertificate.ser"; try { final PrintStream stdout = new PrintStream(new FileOutputStream( ProxyConstants.LOG_FILE)); System.setOut(stdout); } catch (final FileNotFoundException e) { final String currentDir1 = new File("").getAbsolutePath(); JOptionPane.showMessageDialog(null, "Could not access LOG file in : " + currentDir1 + File.separator + "ProxyLog.txt", "Message", JOptionPane.ERROR_MESSAGE); } uiuser(); } public static void uiuser () { final JFrame jd = new JFrame(); final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Dimension screenSize = toolkit.getScreenSize(); final int x = (screenSize.width - jd.getWidth()) / 2; final int y = (screenSize.height - jd.getHeight()) / 2; final JPanel panel = new JPanel(new GridLayout(5, 1)); jd.addWindowListener(new MyWindowListener()); jd.setTitle("Coded by @amir"); jd.setLocation(100, 100); jd.setSize(300, 200); final JButton jb1 = new JButton("شروع"); final JButton jb2 = new JButton("تنظیمات"); final JButton jb3 = new JButton("توقف"); final JButton jb4 = new JButton("درباره"); final JButton jb5 = new JButton(); if(ProxyConstants.sessionid.equals("0")) { jb1.setEnabled(false); } else { JFrame frame; frame = new JFrame(); frame.setSize(200, 100); JOptionPane.showMessageDialog(frame,"hey", "پیام سیستم", JOptionPane.PLAIN_MESSAGE); jb1.setEnabled(true); } jb1.addActionListener(new ButtonListener(jb1, jd, jb5, jb2)); jb2.addActionListener(new ButtonListener(jb2, jd, jb5, jb2)); jb3.addActionListener(new ButtonListener(jb3, jd, jb5, jb2)); jb4.addActionListener(new ButtonListener(jb4, jd, jb5, jb2)); panel.add(jb1); panel.add(jb2); panel.add(jb3); panel.add(jb4); panel.add(jb5); jd.add(panel); jd.show(); } public static void showSettings() { final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Dimension screenSize = toolkit.getScreenSize(); final Settings frame = new Settings(); final int x = (screenSize.width - frame.getWidth()) / 2; final int y = (screenSize.height - frame.getHeight()) / 2; frame.setLocation(100, 100); frame.setSize(500, 500); frame.show(); } } class ButtonListener implements ActionListener { JButton jb; JButton jb5; JButton jb2; JFrame jf; ButtonListener(final JButton jb, JFrame jf, JButton jb5, JButton jb2) { this.jb = jb; this.jf = jf; this.jb5 = jb5; this.jb2 = jb2; }
second file which i need to re enable my jb1 button
RegardsJava Code:if(!ProxyConstants.sessionid.equals("0")) { ProxyUIStarter ui = new ProxyUIStarter(); ui.jb1; String files = currentDir + File.separator+ "bv.jar"; System.exit(0); Runtime.getRuntime().exec(files); }
-
Interesting code here:
What is this supposed to accomplish? Is the runtime exec ever called? I'd be surprised if it is.Java Code:System.exit(0); Runtime.getRuntime().exec(files);
- 04-28-2011, 09:08 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
You need to expose the jb1 Button so the other class can enable it. In your first class, provide a public "get" method that returns a reference to your button. Then in the second class, call that get method to get the reference. Then call setEnabled(true) on that reference.
- 04-28-2011, 09:43 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
thanks FlipPoker@gmail.com
can you give me an example or show me on my source how to do this
cause im very beginner in java
@Fubarable i was moving a code up and down thats why its there
sure it wont work
regards
-
Read up in most any tutorial on getter and setter methods (also called accessor and mutator methods respectively), and you'll see many examples of how to create these critters. You will probably want to study quite a bit in order to be able to handle the depth of coding problems that you are and will be faced with.
Luck
Similar Threads
-
Disable Radio button
By AJG in forum New To JavaReplies: 3Last Post: 05-10-2011, 11:09 AM -
Please help : JSP enable/disable button
By kalyana in forum New To JavaReplies: 3Last Post: 03-24-2011, 05:06 PM -
Disable Maximize button in JFrame?
By Manish87 in forum AWT / SwingReplies: 0Last Post: 02-01-2011, 03:39 PM -
disable a java.awt.Button but not greying it out
By alinaqvi90 in forum AWT / SwingReplies: 4Last Post: 10-18-2010, 01:08 PM -
Disable the WebBrowser Back button
By Deepa in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 11-26-2008, 09:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks