下面ChangeTitle( )中对b1和b2按键构造__,实现当按下b1键时标题变为Students,当按下b2键时标题变为Teachers。添加空缺的语句。
...
public ChangeTitle( )

super("Title Bar");
b1.addActionListener(this);
【11】 ;
Jpanel pane = new Jpane1( );
Pane.add(b1);
Pane.add(b2);
SetContentPane(pane);

public void actionPerformed(ActionEvent evt)

Object sourve = evt.getSource( );
if (sourve ==b1)
setTitle("Students");
else if (source == b2)
setTitle("Teachers");
repaint( );

...

b2.addActionListener(this);

下面ButtonFrame类创建了一个容器,包含有3个按键。
import javax.swing.*;
public class ButtonFrame extends JFrame

JButton Button1= new JButton("Button1");
JButton Button2= new JButton("Button2");
JButton Button3= new JButton("Button3");
public ButtonFrame( )

super("ButtonFrame");
setSize(100,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPane1 pane = new JPanel( );
pane.add(Buttonl);
pane.add(Button2);
pane.add(Button3);
【12】 ;

public static void main(String args[])

ButtonFrame bf= new ButtonFrame( );
bf.show( );


请在程序代码中的画线处添上正确的语句,使程序完整。

setContentPane(pane)

请完成下列Java程序:使用JTabbedPane在窗口顶部建立一个图形标签,包含有两个标签窗格,一个使用简单标签(Labe1)显示欢迎信息,一个使用按钮和图标。 注意:请勿改动main( )主方法和其他已有语句内容,仅在下划线处填入适当的语句。 程序运经结果如下: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ex8_2 extends JPane1 public ex8_2( ) JTabbedPane jtp=new JTabbedPane(SwingConstants.BOTTOM); Icon icon=new ImageIcon("icon.gif"); JButton btn=new JButton(icon); JLabel l=new JLabel("Welcome to the NCR Examination!"); ______________; ______________; setLayout(new BorderLayout( )); add(jtp,"Center"); public static void main(String args[]) ex8_2 obi8_2=new ex8_2( ); String str= obj8_2.getClass( ).toString( ); if(str.indexOf("class") != -1) str = str.substring(6); JFrame frm = new JFrame(str); frm.addWindowListener(new WindowAdapter( ) public void windowClosing(WindowEvent we) System.exit(O); ); frm.getContentPane ( ) .add(obj8_2); frm.setSize(300, 200); frm.setVisible(true);

jtp.addTab(" Icon ",icon,btn)
itp.addTab(" Welcome" ,1)

下面ChangeTitle( )中对b1和b2按钮构造__,实现当单击b1按钮时标题变为 students,当单击b2按钮时标题变为teachers。请将程序补充完整。
public ChangeTitle( )
super("Title Bar");
b1.addActionListener(this);
【15】
Jpanel pane=new Jpane1( );
Pane.add(b1);
Pane.add(b2);
SetContentPane(pane);

public void action Performed(ActionEventevt)
Object sourve=evt.getSource( );
if(sourve==b1”
setTitle(”Students”);
else if(source==b2)
setTitle(”Teachers”);
repaint( );

b2.addActionListener(this);

下面ButtonFrame类创建了一个容器,包含有3个按键。 import javax.swing.*; public class ButtonFrame extends JFrame { JButton Button1= new JButton("Button1"); JButton Button2= new JButton("Button2"); JButton Button3= new JButton("Button3"); public ButtonFrame( ) { super("ButtonFrame"); setSize(100,150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPane1 pane = new JPanel( ); pane.add(Buttonl); pane.add(Button2); pane.add(Button3); 【12】 ; } public static void main(String args[]) { ButtonFrame bf= new ButtonFrame( ); bf.show( ); } } 请在程序代码中的画线处添上正确的语句,使程序完整。

setContentPane(pane)

下面ChangeTitle( )中对b1和b2按钮构造__,实现当单击b1按钮时标题变为 students,当单击b2按钮时标题变为teachers。请将程序补充完整。 public ChangeTitle( ){ super("Title Bar"); b1.addActionListener(this); 【15】 Jpanel pane=new Jpane1( ); Pane.add(b1); Pane.add(b2); SetContentPane(pane); } public void action Performed(ActionEventevt){ Object sourve=evt.getSource( ); if(sourve==b1” setTitle(”Students”); else if(source==b2) setTitle(”Teachers”); repaint( ); }

b2.addActionListener(this);

请完成下列Java程序:使用JTabbedPane在窗口顶部建立一个图形标签,包含有两个标签窗格,一个使用简单标签(Labe1)显示欢迎信息,一个使用按钮和图标。 注意:请勿改动main( )主方法和其他已有语句内容,仅在下划线处填入适当的语句。 程序运经结果如下: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ex8_2 extends JPane1 { public ex8_2( ) { JTabbedPane jtp=new JTabbedPane(SwingConstants.BOTTOM); Icon icon=new ImageIcon("icon.gif"); JButton btn=new JButton(icon); JLabel l=new JLabel("Welcome to the NCR Examination!"); ______________; ______________; setLayout(new BorderLayout( )); add(jtp,"Center"); } public static void main(String args[]){ ex8_2 obi8_2=new ex8_2( ); String str= obj8_2.getClass( ).toString( ); if(str.indexOf("class") != -1) str = str.substring(6); JFrame frm = new JFrame(str); frm.addWindowListener(new WindowAdapter( ) { public void windowClosing(WindowEvent we) { System.exit(O); } }); frm.getContentPane ( ) .add(obj8_2); frm.setSize(300, 200); frm.setVisible(true); } }

下面ChangeTitle( )中对b1和b2按键构造__,实现当按下b1键时标题变为Students,当按下b2键时标题变为Teachers。添加空缺的语句。 ... public ChangeTitle( ) { super("Title Bar"); b1.addActionListener(this); 【11】 ; Jpanel pane = new Jpane1( ); Pane.add(b1); Pane.add(b2); SetContentPane(pane); } public void actionPerformed(ActionEvent evt) { Object sourve = evt.getSource( ); if (sourve ==b1) setTitle("Students"); else if (source == b2) setTitle("Teachers"); repaint( ); } ...

b2.addActionListener(this);

微信扫码获取答案解析
下载APP查看答案解析