import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class GameDifficulty extends JFrame
{
JPanel jp = new JPanel();
JPopupMenu jpm = new JPopupMenu();
JSlider js = new JSlider();
JTextField jtf = new JTextField();
public GameDifficulty()
{
jp =(JPanel)this.getContentPane();
jp.setLayout(null);
jp.setBounds(0,0,400,300);
jpm.setBounds(0,0,400,300);
js.setBounds(100,50,200,60);
// js.setMaximum(100);
js.setMajorTickSpacing(30); //设置滑动条的最大间隔
js.setMinorTickSpacing(10); //设置滑动条的最小间隔
js.setPaintLabels(true); //显示数值标签
js.setPaintTicks(true); //显示最大及最小间隔条
js.setBounds(new Rectangle(40, 59, 216, 47));
jtf.setBounds(150,140,80,30);
jp.add(jpm);
jp.add(js);
jp.add(jtf);
this.setVisible(true);
this.setSize(400,300);
}
public static void main(String [] args)
{
new GameDifficulty();
}
}
以上是我写的,但是跟我想要的效果不一样,首先滚动条不能移动。其次不知道怎么把滚动条的值取出来放到文本框中。望前辈指点!
----------------解决方案--------------------------------------------------------
没有前辈指教一下啊?
----------------解决方案--------------------------------------------------------
[CODE]import javax.swing.*;
import java.awt.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
class GameDifficulty extends JFrame implements ChangeListener {
JPanel jp = new JPanel();
JPopupMenu jpm = new JPopupMenu();
JSlider js = new JSlider();
JTextField jtf = new JTextField();
public GameDifficulty() {
jp =(JPanel)this.getContentPane();
jp.setLayout(null);
jp.setBounds(0,0,400,300);
jpm.setBounds(0,0,400,300);
js.setBounds(100,50,200,60);
js.addChangeListener(this);
// js.setMaximum(100);
js.setMajorTickSpacing(30); //设置滑动条的最大间隔
js.setMinorTickSpacing(10); //设置滑动条的最小间隔
js.setPaintLabels(true); //显示数值标签
js.setPaintTicks(true); //显示最大及最小间隔条
js.setBounds(new Rectangle(40, 59, 216, 47));
jtf.setBounds(150,140,80,30);
// jp.add(jpm);弹出菜单不是这样添加的,所以我把它注释掉了
jp.add(js);
jp.add(jtf);
this.setSize(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//增加了点关闭时的操作,否则你点关闭的时候,你的程序并没有退出
}
public static void main(String [] args) {
new GameDifficulty();
}
public void stateChanged(ChangeEvent e) {
jtf.setText(""+js.getValue());
}
}[/CODE]
帮你改了,你看看吧
----------------解决方案--------------------------------------------------------
谢谢冰峰同志~呵呵,关于接口我今天才刚接触到两个,在昨天写程序的时候还有接口这样的思路~
我要努力在努力
[此贴子已经被作者于2006-12-28 22:44:14编辑过]
----------------解决方案--------------------------------------------------------
XP 虾子不错哦!哈哈!逮到你了!
----------------解决方案--------------------------------------------------------