📄 openurldlg.java
字号:
package javamediaplayer;import java.awt.*;import javax.swing.*;import java.awt.event.*;/** * Title: 使用Java制作的媒体播放器 * Description: 这个播放器利用了Java Media Frame API来实现主要功能 * Copyright: Copyright (c) 2003 * Company: 北京师范大学继续教育学院99计算机应用 * @author 郭汉文 * @version 1.0 */public class OpenUrlDlg extends JDialog { public final static int ACTION_OPEN=1; public final static int ACTION_CANCEL=0; private String nameUrlDefault = null; private int intAction = ACTION_CANCEL; protected JFrame frameOwner = null; JPanel panelInput = new JPanel(); GridLayout gridLayout1 = new GridLayout(); FlowLayout flowLayout1 = new FlowLayout(); JLabel jLabel1 = new JLabel(); JTextField txtURL = new JTextField(); JPanel panelCmd = new JPanel(); JButton cmdOpen = new JButton(); JButton cmdCancel = new JButton(); public OpenUrlDlg(JFrame frame, String nameUrlDefault) { super(frame, "Open Url", true); frameOwner=frame; this.nameUrlDefault =nameUrlDefault; try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public OpenUrlDlg() { this(null, ""); } void jbInit() throws Exception { panelInput.setLayout(flowLayout1); this.setTitle("Open Url"); this.getContentPane().setLayout(gridLayout1); gridLayout1.setRows(2); gridLayout1.setColumns(1); jLabel1.setForeground(Color.red); jLabel1.setText("URL:"); cmdOpen.setBackground(new Color(180, 255, 50)); cmdOpen.setForeground(Color.magenta); cmdOpen.setText("Open"); txtURL.setText(nameUrlDefault); cmdOpen.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cmdOpen_actionPerformed(e); } }); cmdCancel.setBackground(new Color(180, 255, 150)); cmdCancel.setForeground(Color.magenta); cmdCancel.setText("Canel"); cmdCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cmdCancel_actionPerformed(e); } }); panelCmd.setBackground(Color.orange); panelInput.setBackground(Color.orange); panelInput.add(jLabel1, null); panelInput.add(txtURL, null); txtURL.setColumns(30); this.getContentPane().add(panelInput, null); this.getContentPane().add(panelCmd, null); panelCmd.add(cmdOpen, null); panelCmd.add(cmdCancel, null); this.pack(); this.autoPosition() ; this.setResizable ( false ); } public void addNotify () { this.setBackground ( Color.lightGray ); super.addNotify (); autoPosition (); } public void autoPosition () { Dimension dim; Dimension dimFrame; Dimension dimDialog; Dimension dimScreen; Point point; Insets insets; point=frameOwner.getLocationOnScreen(); dimFrame=frameOwner.getSize(); dimDialog=this.getSize(); point.y=point.y+(int)(dimFrame.getHeight()-dimDialog.getHeight())/2; this.setLocation(point) ; } public String getUrl () { String nameUrl; nameUrl = txtURL.getText(); return ( nameUrl ); } void cmdOpen_actionPerformed(ActionEvent e) { this.setAction(this.ACTION_OPEN ); this.dispose() ; } void cmdCancel_actionPerformed(ActionEvent e) { this.setAction(this.ACTION_CANCEL ); this.dispose() ; } protected void setAction ( int intAction ) { this.intAction = intAction; } public int getAction () { return ( intAction ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -