该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Tank;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
public class MainJFrame implements ActionListener,ItemListener{
JFrame frame;
MusicPlay player;
Container contentpane;
Background back;
JPanel panel;
JButton button,button1,button2 ;
JComboBox jbox,jcox;
String str[]={"4","5","6","7","8","9","10"};
String stm[]={"1.mp3","2.mp3"};
String ss;
static int n;
static int num=0;
public MainJFrame(){
frame=new JFrame("测试");
contentpane=frame.getContentPane();
panel=new JPanel();
button=new JButton("棋盘");
button1=new JButton("音乐开始");
button2=new JButton("音乐停止");
jcox=new JComboBox(str);
jbox=new JComboBox(stm);
back=new Background();
panel.add(button);
panel.add(button1);
panel.add(button2);
panel.add(jcox);
panel.add(jbox);
contentpane.add(panel,"North");
panel.setBackground(Color.gray);
contentpane.add(back,"Center");
button.addActionListener(this);
button1.addActionListener(this);
button2.addActionListener(this);
jcox.addItemListener(this);
jbox.addItemListener(this);
inti();
}
public void inti(){
frame.setBounds(100,100,700,800);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MainJFrame();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button)
{
back.repaint();
}
if(e.getSource()==button1)
{
player=new MusicPlay();
player.play.start();
}
if(e.getSource()==button2){
player.play.stop();
}
}
public void itemStateChanged(ItemEvent e) {
if(e.getSource()==jcox){
n=jcox.getSelectedIndex()+4;
}
if(e.getSource()==jbox){
num=jbox.getSelectedIndex();
}
}
}
//
这是主类。