河南成教 / Java程序设计
阅读程序,画出程序运行后的界面并写出程序的功能。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Class3601 implements AdjustmentListener
{
JScrollBar myBar;
JLabel label;
public Class3601(String s)
{
JFrame myWin=new JFrame(s);
Container con=myWin.getContentPane();
con.setLayout(new GridLayout(2,1));
myBar=new JScrollBar(JScrollBar.HORIZONTAL,5,20,0,300);
label=new JLabel(""+myBar.getValue(),JLabel.CENTER);
myBar.addAdjustmentListener(this);
con.add(label);
con.add(myBar);
myWin.setSize(300,100);
myWin.setVisible(true);
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
label.setText(""+e.getAdjustable().getValue());
}
public static void main(String[] args)
{
new Class3601("Class3601");
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Class3601 implements AdjustmentListener
{
JScrollBar myBar;
JLabel label;
public Class3601(String s)
{
JFrame myWin=new JFrame(s);
Container con=myWin.getContentPane();
con.setLayout(new GridLayout(2,1));
myBar=new JScrollBar(JScrollBar.HORIZONTAL,5,20,0,300);
label=new JLabel(""+myBar.getValue(),JLabel.CENTER);
myBar.addAdjustmentListener(this);
con.add(label);
con.add(myBar);
myWin.setSize(300,100);
myWin.setVisible(true);
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
label.setText(""+e.getAdjustable().getValue());
}
public static void main(String[] args)
{
new Class3601("Class3601");
}
}
参考答案:
佳题速递: