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

Poppy_peng 2012-06-10 04:59:18
不好意思的说小妹本学期都在外面实习忽略了神奇的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 );
}
}
);
}
}

...全文
472 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
雨木林风 2012-07-06
  • 打赏
  • 举报
回复
1楼亮了
我就改个名 2012-07-05
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 的回复:]
小妹要是贴个照片出来效果或许会更好
[/Quote]

w晚上哥带你放松一下
mimitracely 2012-06-27
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 的回复:]

引用 19 楼 的回复:

引用 13 楼 的回复:
+10086

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

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1


+1

+1
[/Quote]
+10086
momao_kin 2012-06-27
  • 打赏
  • 举报
回复
没有正经回帖的啊。lz不说自己是小妹可能效果会好点。嘻嘻
zenghui107 2012-06-27
  • 打赏
  • 举报
回复
小妹个毛,没看见是当天注册的信号?
  • 打赏
  • 举报
回复
小妹,难道你不知道CSDN是狼窝么???
噢噢噢噢 2012-06-27
  • 打赏
  • 举报
回复
一B之力!
actsai 2012-06-27
  • 打赏
  • 举报
回复
小妹要是贴个照片出来效果或许会更好
戏子 2012-06-26
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 的回复:]

引用 13 楼 的回复:
+10086

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

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1


+1
[/Quote]
+1
sjmhai 2012-06-25
  • 打赏
  • 举报
回复
10086吧
ll894311655 2012-06-25
  • 打赏
  • 举报
回复
看来要挂了。。。。呵呵
Yynynyn 2012-06-25
  • 打赏
  • 举报
回复
哎呀,来晚了。。。
Left_you 2012-06-25
  • 打赏
  • 举报
回复
小妹对不起,哥来晚了!
蓝湛江 2012-06-25
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]
+10086

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

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1
[/Quote]

+1
蓝湛江 2012-06-25
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]
+10086

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

引用 2 楼 的回复:

楼上高手啊

+1

++

+1

+1
[/Quote]

+1
孤独人生 2012-06-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

这就是中国教学啊,不用的偏门的,最爱考,这样才成就的出学出来无用撒,凸显出我的老师很牛B撒,
[/Quote]

严重同意啊,我java其他地方都学的还行,就是对这块没有什么兴趣,因为知道基本上用不到,阿弥有想到你们老师让你们解释这个东东。。。无语。。。
qqliang1314 2012-06-20
  • 打赏
  • 举报
回复
小妹,你们java老师这题出的,水平也忒高了
aj_qb0632 2012-06-20
  • 打赏
  • 举报
回复
哈哈哈哈 小妹加油努力啊
mckellening 2012-06-13
  • 打赏
  • 举报
回复
奔着小妹标题来看看的
Enagle_Wang 2012-06-12
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]
引用 3 楼 的回复:

引用 2 楼 的回复:

楼上高手啊

++

+1
[/Quote]
+1
加载更多回复(13)

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧