📄 filetransferpanel.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.bluetooth.*;
public class FileTransferPanel extends JPanel implements ActionListener{
JButton connectButton = new JButton("Connect");
JButton exitButton = new JButton("Exit");
JTextArea textarea = new JTextArea("",10, 25);
File file = null;
JFrame frame = null;
String connectionURL = null;
RemoteDevice remoteDevice = null;
public FileTransferPanel(JFrame frame, File file, String connectionURL){
this.frame = frame;
this.file = file;
this.connectionURL = connectionURL;
Font font = new Font("Arial", Font.PLAIN, 12);
setBackground(Color.WHITE);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
ImageIcon headerIcon = new ImageIcon("header1.gif","image header");
JLabel headerLabel = new JLabel(headerIcon);
headerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
add(headerLabel);
ImageIcon spacerIcon1 = new ImageIcon("spacer30.gif","image spacer");
JLabel spacerLabel1 = new JLabel(spacerIcon1);
spacerLabel1.setAlignmentX(Component.CENTER_ALIGNMENT);
add(spacerLabel1);
JLabel textlabel1 = new JLabel("The music file: " + file.getName());
textlabel1.setAlignmentX(Component.CENTER_ALIGNMENT);
textlabel1.setFont(font);
add(textlabel1);
JLabel textlabel2 = new JLabel("is now being transferred to the selected Bluetooth device. ");
textlabel2.setAlignmentX(Component.CENTER_ALIGNMENT);
textlabel2.setFont(font);
add(textlabel2);
connectButton.setAlignmentX(Component.CENTER_ALIGNMENT);
connectButton.addActionListener(this);
add(connectButton);
ImageIcon spacerIcon2 = new ImageIcon("spacer30.gif","image spacer");
JLabel spacerLabel2 = new JLabel(spacerIcon2);
spacerLabel2.setAlignmentX(Component.CENTER_ALIGNMENT);
add(spacerLabel2);
JScrollPane scrollPane = new JScrollPane(textarea);
textarea.setEditable(false);
scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
add(scrollPane);
ImageIcon spacerIcon3 = new ImageIcon("spacer10.gif","image spacer");
JLabel spacerLabel3 = new JLabel(spacerIcon3);
spacerLabel3.setAlignmentX(Component.CENTER_ALIGNMENT);
add(spacerLabel3);
JLabel textlabel3 = new JLabel("Please click on the EXIT button to exit. ");
textlabel3.setAlignmentX(Component.CENTER_ALIGNMENT);
textlabel3.setFont(font);
add(textlabel3);
ImageIcon spacerIcon4 = new ImageIcon("spacer10.gif","image spacer");
JLabel spacerLabel4 = new JLabel(spacerIcon3);
spacerLabel4.setAlignmentX(Component.CENTER_ALIGNMENT);
add(spacerLabel4);
exitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
exitButton.addActionListener(this);
add(exitButton);
ImageIcon spacerIcon5 = new ImageIcon("spacer10.gif","image spacer");
JLabel spacerLabel5 = new JLabel(spacerIcon3);
spacerLabel5.setAlignmentX(Component.CENTER_ALIGNMENT);
add(spacerLabel5);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == connectButton) {
ObjectPusher objectPusher = new ObjectPusher(this, file, connectionURL);
objectPusher.start();
}
if (e.getSource() == exitButton) {
System.exit(0);
}
}
public void updateStatus(String message){
textarea.append("\n" + message);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -