当前位置:编程学习 > JAVA >>

小妹明天考试.. 哥哥姐姐可否助一臂之力~!

不好意思的说小妹本学期都在外面实习忽略了神奇的Java课程 可是眼看明天就要考试了呀~~!!
考试的内容就是解释以下十段程序中代码的意思~ 。。 
我知道这样很过分。。
如果各位java大神能来稍稍帮助一下 小妹不挂就有希望了~~!!
每人一段~ 分段感谢!!!

第一段:
// Fig. 12.25: BorderLayoutDemo.java
// Demonstrating BorderLayout.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class BorderLayoutDemo extends JFrame
                              implements ActionListener {
   private JButton b[];
   private String names[] =
      { "Hide North", "Hide South", "Hide East",
        "Hide West", "Hide Center" };
   private BorderLayout layout;

   public BorderLayoutDemo()
   {
      super( "BorderLayout Demo" );

      layout = new BorderLayout( 5, 5 );

      Container c = getContentPane();
      c.setLayout( layout );

      // instantiate button objects
      b = new JButton[ names.length ];

      for ( int i = 0; i < names.length; i++ ) {
         b[ i ] = new JButton( names[ i ] );
         b[ i ].addActionListener( this );
      }

      // order not important
      c.add( b[ 0 ], BorderLayout.NORTH );  // North position
      c.add( b[ 1 ], BorderLayout.SOUTH );  // South position
      c.add( b[ 2 ], BorderLayout.EAST );   // East position
      c.add( b[ 3 ], BorderLayout.WEST );   // West position
      c.add( b[ 4 ], BorderLayout.CENTER ); // Center position

      setSize( 300, 200 );
      show();
   }            

   public void actionPerformed( ActionEvent e )
   {
      for ( int i = 0; i < b.length; i++ ) 
         if ( e.getSource() == b[ i ] )
            b[ i ].setVisible( false );
         else
            b[ i ].setVisible( true );

      // re-layout the content pane
      layout.layoutContainer( getContentPane() );
   }

   public static void main( String args[] )
   { 
      BorderLayoutDemo app = new BorderLayoutDemo();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );

第二段:
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;


public class Button2Applet extends Applet implements ActionListener{

boolean circlemark=true;
String name;
Button b1;
Button b2;

    public void init()
   { Button b1=new Button("圆");
     Button b2=new Button("方");
     add(b1); 
     add(b2);
     name="";
     b1.addActionListener(this);
     b2.addActionListener(this);
   }

public void actionPerformed( ActionEvent e )
    {  
if (e.getActionCommand()=="圆") {circlemark=true;}
    else {circlemark=false;}
repaint();  
 }

public void paint(Graphics g)
   { if (circlemark)
         g.fillOval(10,10,30,30);
     else
         g.fillRect(20,20,40,40);

第三段:
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;


public class ButtonApplet extends Applet implements ActionListener{
int CurrentMarks=0;

public void init()
{
Button b1=new Button("按钮");
    add(b1);  
b1.addActionListener(this);
}

public void actionPerformed( ActionEvent e )
    {
CurrentMarks++;
    repaint();   
    }
public void paint(Graphics g)
   { g.drawString(" "+CurrentMarks,10,10);}

第四段:
// Fig. 12.10: ButtonTest.java
// Creating JButtons.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ButtonTest extends JFrame {
   private JButton plainButton, fancyButton;

   public ButtonTest()
   {
      super( "Testing Buttons" );

      Container c = getContentPane();
      c.setLayout( new FlowLayout() );

      // create buttons
      plainButton = new JButton( "Plain Button" );
      c.add( plainButton );

      Icon bug1 = new ImageIcon( "bug1.gif" );
      Icon bug2 = new ImageIcon( "bug2.gif" );
      fancyButton = new JButton( "Fancy Button", bug1 );
      fancyButton.setRolloverIcon( bug2 );
      c.add( fancyButton ); 

      // create an instance of inner class ButtonHandler
      // to use for button event handling 
      ButtonHandler handler = new ButtonHandler();
      fancyButton.addActionListener( handler );
      plainButton.addActionListener( handler );

      setSize( 275, 100 );
      show();
   }

   public static void main( String args[] )
   { 
      ButtonTest app = new ButtonTest();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }

   // inner class for button event handling
   private class ButtonHandler implements ActionListener {
      public void actionPerformed( ActionEvent e )
      {
         JOptionPane.showMessageDialog( null,
            "You pressed: " + e.getActionCommand() );
      }
   }
}


第五段:
// Fig. 12.11: CheckBoxTest.java
// Creating Checkbox buttons.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class checkbox extends JFrame {
   private JTextField t;
   private JCheckBox bold, italic;

   public checkbox()
   {
      super( "JCheckBox Test" );

      Container c = getContentPane();
      c.setLayout(new FlowLayout());

      t = new JTextField( "Watch the font style change", 20 );
      t.setFont( new Font( "TimesRoman", Font.PLAIN, 14 ) );
      c.add( t );

      // create checkbox objects
      bold = new JCheckBox( "Bold" );
      c.add( bold );     

      italic = new JCheckBox( "Italic" );
      c.add( italic );

      CheckBoxHandler handler = new CheckBoxHandler();
      bold.addItemListener( handler );
      italic.addItemListener( handler );

      setSize( 275, 100 );
      show();
   }

   public static void main( String args[] )
   { 
   checkbox app = new checkbox();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }

   private class CheckBoxHandler implements ItemListener {
      private int valBold = Font.PLAIN;
      private int valItalic = Font.PLAIN;

      public void itemStateChanged( ItemEvent e )
      {
         if ( e.getSource() == bold )
            if ( e.getStateChange() == ItemEvent.SELECTED )
               valBold = Font.BOLD;
            else
               valBold = Font.PLAIN;
               
         if ( e.getSource() == italic )
            if ( e.getStateChange() == ItemEvent.SELECTED )
               valItalic = Font.ITALIC;
            else
               valItalic = Font.PLAIN;

         t.setFont(
            new Font( "TimesRoman", valBold + valItalic, 14 ) );
         t.repaint();
      }
   }
}

第六段:
// Fig. 12.22: KeyDemo.java
// Demonstrating keystroke events.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class KeyDemo extends JFrame implements KeyListener {
   private String line1 = "", line2 = "";
   private String line3 = "";
   private JTextArea textArea;

   public KeyDemo()
   {
      super( "Demonstrating Keystroke Events" );

      textArea = new JTextArea( 10, 15 );
      textArea.setText( "Press any key on the keyboard..." );
      textArea.setEnabled( false );

      // allow frame to process Key events
      addKeyListener( this );

      getContentPane().add( textArea );  

      setSize( 350, 100 );
      show();
   }

   public void keyPressed( KeyEvent e )
   {
      line1 = "Key pressed: " +
               e.getKeyText( e.getKeyCode() );
      setLines2and3( e );
   }

   public void keyReleased( KeyEvent e )
   {
      line1 = "Key released: " +
               e.getKeyText( e.getKeyCode() );
      setLines2and3( e );
   }

   public void keyTyped( KeyEvent e )
   {
      line1 = "Key typed: " + e.getKeyChar();
      setLines2and3( e );
   }

   private void setLines2and3( KeyEvent e )
   {
      line2 = "This key is " +
              ( e.isActionKey() ? "" : "not " ) +
              "an action key";

      String temp = 
         e.getKeyModifiersText( e.getModifiers() );

      line3 = "Modifier keys pressed: " +
              ( temp.equals( "" ) ? "none" : temp );

      textArea.setText(
         line1 + "\n" + line2 + "\n" + line3 + "\n" );
   }

   public static void main( String args[] )
   {
      KeyDemo app = new KeyDemo();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }
}

--------------------编程问答-------------------- 小妹的程序太长了,不知道咋样给你讲解啊~~~
qq里说好 --------------------编程问答-------------------- 楼上高手啊 --------------------编程问答--------------------
引用 2 楼  的回复:
楼上高手啊

++ --------------------编程问答-------------------- 你们考试为啥都是swing/applet的东西,都很少用了 --------------------编程问答-------------------- 扣脚大汉请自重 --------------------编程问答-------------------- 这就是中国教学啊,不用的偏门的,最爱考,这样才成就的出学出来无用撒,凸显出我的老师很牛B撒, --------------------编程问答-------------------- 应用程序? --------------------编程问答-------------------- 一楼亮了  --------------------编程问答-------------------- 小妹真牛,这题,也太多了吧,怎么说啊! --------------------编程问答-------------------- 若不是看小妹两字,贴都懒着回。 --------------------编程问答--------------------
引用 3 楼  的回复:
引用 2 楼  的回复:

楼上高手啊

++

+1 --------------------编程问答--------------------
引用 11 楼  的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

++

+1

+1 --------------------编程问答-------------------- +10086
引用 12 楼  的回复:
引用 11 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

++

+1

+1
--------------------编程问答--------------------
引用 13 楼  的回复:
+10086
引用 12 楼  的回复:
引用 11 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

++

+1

+1

+1008611 --------------------编程问答-------------------- 奔着小妹标题来看看的 --------------------编程问答-------------------- 哈哈哈哈  小妹加油努力啊  --------------------编程问答-------------------- 小妹,你们java老师这题出的,水平也忒高了 --------------------编程问答--------------------
引用 6 楼  的回复:
这就是中国教学啊,不用的偏门的,最爱考,这样才成就的出学出来无用撒,凸显出我的老师很牛B撒,


严重同意啊,我java其他地方都学的还行,就是对这块没有什么兴趣,因为知道基本上用不到,阿弥有想到你们老师让你们解释这个东东。。。无语。。。 --------------------编程问答--------------------
引用 13 楼  的回复:
+10086

引用 12 楼 的回复:
引用 11 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1


+1 --------------------编程问答--------------------
引用 13 楼  的回复:
+10086

引用 12 楼 的回复:
引用 11 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1


+1 --------------------编程问答-------------------- 小妹对不起,哥来晚了! --------------------编程问答-------------------- 哎呀,来晚了。。。 --------------------编程问答-------------------- 看来要挂了。。。。呵呵 --------------------编程问答-------------------- 10086吧 --------------------编程问答--------------------
引用 19 楼  的回复:
引用 13 楼  的回复:
+10086

引用 12 楼 的回复:
引用 11 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1


+1

+1 --------------------编程问答--------------------
引用 25 楼  的回复:
引用 19 楼  的回复:

引用 13 楼  的回复:
+10086

引用 12 楼 的回复:
引用 11 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1


+1

+1

+10086 --------------------编程问答-------------------- 一B之力! --------------------编程问答-------------------- 小妹,难道你不知道CSDN是狼窝么??? --------------------编程问答-------------------- 小妹个毛,没看见是当天注册的信号? --------------------编程问答-------------------- 没有正经回帖的啊。lz不说自己是小妹可能效果会好点。嘻嘻 --------------------编程问答-------------------- 小妹要是贴个照片出来效果或许会更好 --------------------编程问答--------------------
引用 31 楼  的回复:
小妹要是贴个照片出来效果或许会更好


w晚上哥带你放松一下 --------------------编程问答-------------------- 1楼亮了
补充:Java ,  非技术区
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,