当前位置:网站首页 > Java基础 > 正文

java100个基础小程序

/

* @(#)CardLayoutDemo.java

*

*

* @author

* @version java100个基础小程序 1.00 2008/8/10

*/

import java.awt.*;

import java.awt.event.*;

public class CardLayoutDemo extends Frame{

/

*

*/

private static final long serialVersionUID = 1L;

/

* Creates a new instance of <code>CardLayoutDemo</code>.

*/

Panel pnlCommondArea=new Panel();

Panel pnlDisplayArea=new Panel();

CardLayout cardlayout1=new CardLayout();

Button btnFirst=new Button("第一个");

Button btnPrevious=new Button("前一个");

Button btnNext=new Button("后一个");

Button btnLast=new Button("最后一个");

public CardLayoutDemo() {

this.setLayout(new BorderLayout());

this.add(pnlCommondArea,BorderLayout.NORTH);

this.add(pnlDisplayArea,BorderLayout.CENTER);

pnlDisplayArea.setLayout(cardlayout1);

Panel pnlFirst=new Panel();

pnlFirst.setBackground(Color.blue);

pnlFirst.setForeground(Color.white); //设置字的颜色

pnlDisplayArea.add("first",pnlFirst);

pnlFirst.add(new Label("This is the first Panel!"));

Panel pnlSecond=new Panel();

pnlSecond.setBackground(Color.red);

pnlSecond.setForeground(Color.blue);

pnlDisplayArea.add("second",pnlSecond);

pnlSecond.add(new Label("This is the second Panel!"));

Panel pnlThird=new Panel();

pnlThird.setBackground(Color.black);

pnlThird.setForeground(Color.white);

pnlDisplayArea.add("third",pnlThird);

pnlThird.add(new Label("This is the third Panel!"));

Panel pnlFourth=new Panel();

pnlFourth.setBackground(Color.green);

pnlFourth.setForeground(Color.black);

pnlDisplayArea.add("fourth",pnlFourth);

pnlFourth.add(new Label("This is the fourth Panel!"));

Panel pnlFifth=new Panel();

pnlFifth.setBackground(Color.cyan);

pnlFifth.setForeground(Color.GRAY);

pnlDisplayArea.add("fifth",pnlFifth);

pnlFifth.add(new Label("This is the fifth Panel!"));

btnFirst.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

processAction(e);

}

});

btnPrevious.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

processAction(e);

}

});

btnNext.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

processAction(e);

}

});

btnLast.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

processAction(e);

}

});

pnlCommondArea.add(btnFirst);

pnlCommondArea.add(btnPrevious);

pnlCommondArea.add(btnNext);

pnlCommondArea.add(btnLast);

}

/

* @param args the command line arguments

*/

@SuppressWarnings("deprecation")

public static void main(String[] args) {

// TODO code application logic here

CardLayoutDemo frmCardLayout=new CardLayoutDemo();

frmCardLayout.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

});

frmCardLayout.pack();

frmCardLayout.show();

}

public Dimension getPreferredSize()

{

return new Dimension(300,300);

}

private void processAction(ActionEvent e)

{

Button btnEvent=(Button)e.getSource();

if(btnEvent.equals(btnFirst))

cardlayout1.first(pnlDisplayArea);

else if(btnEvent.equals(btnLast))

cardlayout1.last(pnlDisplayArea);

else if(btnEvent.equals(btnPrevious))

cardlayout1.previous(pnlDisplayArea);

else if(btnEvent.equals(btnNext))

cardlayout1.next(pnlDisplayArea);

}

版权声明


相关文章:

  • java基础的教学目标2024-10-17 21:50:01
  • java基础考试及解析2024-10-17 21:50:01
  • 只会java基础简历怎么写2024-10-17 21:50:01
  • java基础小白竖屏2024-10-17 21:50:01
  • java从基础到放弃2024-10-17 21:50:01
  • java基础饭馆点餐2024-10-17 21:50:01
  • java基础的代码固定格式2024-10-17 21:50:01
  • java基础66讲2024-10-17 21:50:01
  • java开发基础学校2024-10-17 21:50:01
  • java 基础计算代码2024-10-17 21:50:01