📄 mpdialog.java
字号:
package edu.uiuc.cs.cs327.linuxwifi.gui;
import edu.uiuc.cs.cs327.linuxwifi.services.*;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JTextField;
import javax.swing.*;
import java.beans.*; //Property change stuff
import java.awt.*;
import java.awt.event.*;
class MPDialog extends JDialog {
private JOptionPane optionPane;
public boolean DoSave = false;
final JTextField textArtist = new JTextField(40);
final JTextField textSong = new JTextField(40);
final JTextField textGenre = new JTextField(40);
final JTextField textFormat = new JTextField(10);
final JTextField textSize = new JTextField(20);
public MPDialog(Frame aFrame, String aWord, PrefScreen parent) {
super(aFrame, true);
final PrefScreen dd = parent;
setSize(new Dimension(400,300));
setLocation(100, 100);
setTitle("Music Profile");
final String msgArtist = "Artist";
final String msgSong = "Song:";
final String msgGenre = "Genre:";
final String msgFormat = "Format:";
final String msgSize = "Size:";
Object[] array = {msgArtist, textArtist, msgSong, textSong, msgGenre, textGenre, msgFormat, textFormat, msgSize, textSize};
final String btnAdd = "Add";
final String btnCancel = "Cancel";
Object[] options = {btnAdd, btnCancel};
optionPane = new JOptionPane(array,
JOptionPane.PLAIN_MESSAGE,
JOptionPane.YES_NO_OPTION,
null,
options,
options[0]);
setContentPane(optionPane);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
/*
* Instead of directly closing the window,
* we're going to change the JOptionPane's
* value property.
*/
optionPane.setValue(new Integer(
JOptionPane.CLOSED_OPTION));
}
});
optionPane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (isVisible()
&& (e.getSource() == optionPane)
&& (prop.equals(JOptionPane.VALUE_PROPERTY) ||
prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
Object value = optionPane.getValue();
if (value == JOptionPane.UNINITIALIZED_VALUE) {
//ignore reset
return;
}
// Reset the JOptionPane's value.
// If you don't do this, then if the user
// presses the same button next time, no
// property change event will be fired.
optionPane.setValue(
JOptionPane.UNINITIALIZED_VALUE);
// Add pressed
if (value.equals(btnAdd)){
String sArtist = textArtist.getText();
DebugOut("Artist=" + sArtist);
if ( !sArtist.equals("") ) {
DoSave = true;
setVisible(false);
}
}
if (value.equals(btnCancel)) {
if (value.equals(btnCancel)){
DoSave = false;
setVisible(false);
}
}
} else { // user closed dialog or clicked cancel
//setVisible(false);
}
}
});
}
MusicProfile getMusicProfile() {
MusicProfile mp = new MusicProfile();
mp.setArtist(textArtist.getText());
mp.setSong(textSong.getText());
mp.setGenre(textGenre.getText());
mp.setFileFormat(textFormat.getText());
int nSize = 0;
try
{
nSize = Integer.parseInt(textSize.getText());
}
catch (NumberFormatException ex) {
;
}
mp.setMaxFileSize(nSize);
return mp;
}
private void DebugOut(String sStr)
{
System.out.println(sStr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -