The Artima Developer Community
Sponsored Link

Java Buzz Forum
Friday Java Quiz: What Will The GUI Show?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Friday Java Quiz: What Will The GUI Show? Posted: Jul 2, 2010 6:23 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Friday Java Quiz: What Will The GUI Show?
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

1    import javax.swing.*; 
2    import java.awt.*; 
3    import java.awt.event.*; 
4     
5    public class Foo { 
6        public static void main(final String[] args) { 
7            EventQueue.invokeLater(new Runnable() { 
8                public void run() { 
9                    swingMain(); 
10               } 
11           }); 
12       } 
13    
14       private static void swingMain() { 
15           JFrame frame = new JFrame("Demo"); 
16           frame.setLayout(new FlowLayout()); 
17    
18           JTextField tf1 = new JTextField(20); 
19           final JTextField tf2 = new JTextField(20); 
20           JButton b = new JButton("Click Me"); 
21    
22           tf1.addFocusListener(new FocusAdapter() { 
23               @Override 
24               public void focusLost(FocusEvent e) { 
25                   tf2.setText("Lost Focus!"); 
26               } 
27           }); 
28    
29           b.addActionListener(new ActionListener() { 
30               public void actionPerformed(ActionEvent e) { 
31                   tf2.setText("Clicked!"); 
32               } 
33           }); 
34    
35           frame.add(tf1); 
36           frame.add(tf2); 
37           frame.add(b); 
38           frame.pack(); 
39           frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
40           frame.setVisible(true); 
41       } 
42   }

Q: If, after starting the above Swing program, you click on the JButton b, what will the JTextField jt2 show?
Lost Focus!
or
Clicked!

Strict rule apply: no compiling and running, no Googling, and your first answer is the final answer. You are allowed to read the Javadoc of the relevant classes though.

Read: Friday Java Quiz: What Will The GUI Show?

Topic: Barnes & Noble 4th-quarter loss widens as it invests in electronic book technology Previous Topic   Next Topic Topic: Analyst raises estimates on Micron on higher prices, healthy demand; shares close up 6 percent

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use