⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window02.java

📁 有选择歌曲的功能
💻 JAVA
字号:
package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import utiloper.Oper;

public class Window02 extends JFrame implements ActionListener,WindowListener {

	SimpleDialog08 dialog08;
	SimpleDialog09 dialog09;
	SimpleDialog10 dialog10;
	String lineSeparator;
	public JTextArea  textArea;
	JScrollPane sp;
	String[] colorNames = {"red","blue","green","black","yellow","pink","white","orange"};
	Color[] colors = {Color.RED,Color.BLUE,Color.GREEN,Color.BLACK,Color.YELLOW,Color.PINK,Color.WHITE,Color.ORANGE};
	public void dgWindow(){
		Container container=this.getContentPane();
		textArea=new JTextArea (8,28);
		textArea.setEditable(false);
		sp = new JScrollPane(textArea);
		JButton jbutton01=new JButton("显示全部歌曲");
		JButton jbutton02=new JButton("按歌曲名查询");
		JButton jbutton03=new JButton("按歌手名查询");
		JButton jbutton04=new JButton("按性别  查询");
		JButton jbutton05=new JButton("播放");
		JButton jbutton06=new JButton("退出");
		JButton jbutton07=new JButton();
		JButton jbutton08=new JButton();
		jbutton07.setIcon(new ImageIcon(getClass().getResource("d.jpg")));
		
		
		JPanel jp01=new JPanel();
		JPanel jp02=new JPanel();
		
		jp01.add(jbutton01);
		jp01.add(jbutton02);
		jp01.add(jbutton03);
		jp01.add(jbutton04);
		jp02.add(jbutton05);
		jp02.add(jbutton06);
		
		addWindowListener(this);
		jbutton01.addActionListener(this);
		jbutton02.addActionListener(this);
		jbutton03.addActionListener(this);
		jbutton04.addActionListener(this);
		jbutton05.addActionListener(this);
		jbutton06.addActionListener(this);
		
		jp01.setLayout(new GridLayout(4,1));
		jp02.setLayout(new GridLayout(2,1));
		BorderLayout bl=new BorderLayout();
		
		container.add(jbutton07,BorderLayout.NORTH);
		container.add(jbutton08,BorderLayout.SOUTH);
		container.add(jp01,BorderLayout.WEST);
		container.add(jp02,BorderLayout.EAST);
		container.add(sp,BorderLayout.CENTER);
		
		jbutton07.setBackground(colors[3]);
		jbutton08.setBackground(colors[3]);
		textArea.setBackground(colors[7]);
		
		lineSeparator = System.getProperty("line.separator");
		
		setTitle("前台");
		setVisible(true);		
		pack();
		this.scroll();
		
	}
	
	public void scroll() {
		textArea.setPreferredSize(new Dimension(1000, 1000));
		textArea.revalidate();
		this.pack();
		this.setVisible(true);
	}
	
	
	public static void main(String[] args) {
		Window02 wd=new Window02();
		wd.dgWindow();

	}
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getActionCommand().equals("退出")){
			System.exit(0);
		}
		else if(arg0.getActionCommand().equals("显示全部歌曲")){
			Oper.queryInfo(this);
		}
		else if(arg0.getActionCommand().equals("播放")){
			System.out.println("ooooooooo");
		}
		else if(arg0.getActionCommand().equals("按歌曲名查询")){
			if(dialog08==null){
			 dialog08=new SimpleDialog08(this,"请输入歌曲名");
				}
			dialog08.setVisible(true);
		}
		else if(arg0.getActionCommand().equals("按歌手名查询")){
			if(dialog09==null){
				 dialog09=new SimpleDialog09(this,"请输入歌手名");
					}
				dialog09.setVisible(true);
		}
		else if(arg0.getActionCommand().equals("按性别  查询")){
			if(dialog10==null){
				 dialog10=new SimpleDialog10(this,"请输入(男/女)");
					}
			dialog10.setVisible(true);
		}
	 }
	public void setText(String text) {
		textArea.append(text + lineSeparator);
	}

	
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void windowClosing(WindowEvent arg0) {
		System.exit(0);
		
	}
	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
class SimpleDialog08 extends JDialog implements ActionListener {

	JTextField field;	
	Window02 parent;
	JButton setButton;
	
	SimpleDialog08(JFrame prentFrame, String title) {
		
		super(prentFrame, title, false);
		parent = (Window02) prentFrame;

		JPanel p1 = new JPanel();
		JLabel label = new JLabel("请输入");
		p1.add(label);
		field = new JTextField(15);
		field.addActionListener(this);
		p1.add(field);
		getContentPane().add("Center", p1);		
	
		JPanel p2 = new JPanel();
		p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton cancelButton = new JButton("取 消");
		cancelButton.addActionListener(this);
		setButton = new JButton("确 定");
		setButton.addActionListener(this);
		p2.add(setButton);
		p2.add(cancelButton);
		getContentPane().add("South", p2);

		pack();
	}
	
	public void actionPerformed(ActionEvent event) {

		Object source = event.getSource();
		if ((source == setButton)) {
			parent.setText(field.getText());
			Oper.lookGname(field.getText(),parent);	
		}
		field.selectAll();
		setVisible(false);
	}
}
class SimpleDialog09 extends JDialog implements ActionListener {

	JTextField field;	
	Window02 parent;
	JButton setButton;
	
	SimpleDialog09(JFrame prentFrame, String title) {
		
		super(prentFrame, title, false);
		parent = (Window02) prentFrame;

		JPanel p1 = new JPanel();
		JLabel label = new JLabel("请输入");
		p1.add(label);
		field = new JTextField(15);
		field.addActionListener(this);
		p1.add(field);
		getContentPane().add("Center", p1);		
	
		JPanel p2 = new JPanel();
		p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton cancelButton = new JButton("取 消");
		cancelButton.addActionListener(this);
		setButton = new JButton("确 定");
		setButton.addActionListener(this);
		p2.add(setButton);
		p2.add(cancelButton);
		getContentPane().add("South", p2);

		pack();
	}
	
	public void actionPerformed(ActionEvent event) {

		Object source = event.getSource();
		if ((source == setButton)) {
			parent.setText(field.getText());
			Oper.lookName(field.getText(), parent);
		}
		field.selectAll();
		setVisible(false);
	}
}
class SimpleDialog10 extends JDialog implements ActionListener {

	JTextField field;	
	Window02 parent;
	JButton setButton;
	
	SimpleDialog10(JFrame prentFrame, String title) {
		
		super(prentFrame, title, false);
		parent = (Window02) prentFrame;

		JPanel p1 = new JPanel();
		JLabel label = new JLabel("请输入");
		p1.add(label);
		field = new JTextField(15);
		field.addActionListener(this);
		p1.add(field);
		getContentPane().add("Center", p1);		
	
		JPanel p2 = new JPanel();
		p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton cancelButton = new JButton("取 消");
		cancelButton.addActionListener(this);
		setButton = new JButton("确 定");
		setButton.addActionListener(this);
		p2.add(setButton);
		p2.add(cancelButton);
		getContentPane().add("South", p2);

		pack();
	}
	
	public void actionPerformed(ActionEvent event) {

		Object source = event.getSource();
		if ((source == setButton)) {
			parent.setText(field.getText());
			Oper.lookSex(field.getText(), parent);
		}
		field.selectAll();
		setVisible(false);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -