📄 netbar.java~2~
字号:
time = time.substring(0, 8);
JLabel lbl2 = new JLabel(time);
c.add(lbl2);
JButton btnok = new JButton("确定");
c.add(btnok, BorderLayout.CENTER);
JButton btnquit = new JButton("取消");
btnquit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fmain.show();
}
});
c.add(btnquit, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == munstart) {
fstart.setVisible(true);
fmain.hide();
} else if (e.getSource() == munend) {
fend.setVisible(true);
fmain.hide();
} else if (e.getSource() == munread) {
fcselect.showOpenDialog(this);
File f;
FileInputStream fi;
try {
f = new File(fcselect.getSelectedFile().getPath());
fi = new FileInputStream(f);
byte[] a = new byte[10 * 1024];
int len = fi.read(a);
textread.append(new String(a, 0, len));
} catch (Exception ex) {
;
}
} else if (e.getSource() == btnstart) {
fstart.show();
fmain.hide();
} else if (e.getSource() == btnok) {
if (text1.getSelectedItem().equals("bill") &&
text2.getText().equals("123") ||
text1.getSelectedItem().equals("zhang") &&
text2.getText().equals("456")) {
fmain.show();
flogin.hide();
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
flogin.show();
}
} else if (e.getSource() == btncancel) {
System.exit(1);
}
}
void Flogin() {
flogin = new JFrame("登陆");
Container c = flogin.getContentPane();
c.setLayout(new GridLayout(3, 3, 5, 5));
flogin.setDefaultCloseOperation(flogin.EXIT_ON_CLOSE);
flogin.setSize(new Dimension(310, 155));
JLabel lbluser;
JLabel lblpaw;
lbluser = new JLabel("用户名", SwingConstants.CENTER);
lblpaw = new JLabel("密码", SwingConstants.CENTER);
text1 = new JComboBox();
try {
String str = "select * from login";
ResultSet res = sta.executeQuery(str);
while (res.next()) {
text1.addItem(res.getString(1));
}
} catch (Exception ex) {
}
text2 = new JTextField(5);
btnok = new JButton("确定");
btnok.addActionListener(this);
btncancel = new JButton("取消");
btncancel.addActionListener(this);
c.add(lbluser);
c.add(text1);
c.add(lblpaw);
c.add(text2);
c.add(btnok);
c.add(btncancel);
flogin.setLocation(380, 300);
flogin.setVisible(true);
}
}
class SwingProgressBarExample extends JPanel {
JProgressBar pbar;
JFrame frame;
JLabel label;
ImageIcon image4 = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"1.jpg"));
public SwingProgressBarExample() {
label = new JLabel();
label.setIcon(image4);
add(label);
pbar = new JProgressBar();
add(pbar);
}
public void updateBar(int newValue) {
pbar.setValue(newValue);
}
void add(final SwingProgressBarExample it) {
frame = new JFrame("待命");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(it);
frame.setSize(450, 350);
frame.setLocation(300, 200);
frame.setVisible(true);
for (int i = 0; i <= 100; i++) {
final int percent = i;
try {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
it.updateBar(percent);
}
});
java.lang.Thread.sleep(50);
} catch (InterruptedException e) {
;
}
}
}
void close() {
frame.hide();
}
}
class MovePicture extends JComponent implements ActionListener {
javax.swing.Timer animator;
ImageIcon icon[] = new ImageIcon[6];
int tmpScale;
final static int numImages = 6;
double x[] = new double[numImages];
double y[] = new double[numImages];
int xh[] = new int[numImages];
int yh[] = new int[numImages];
double scale[] = new double[numImages];
public MovePicture() {
setBackground(Color.blue);
icon[0] = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"01.gif"));
icon[1] = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"02.gif"));
icon[2] = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"03.gif"));
icon[3] = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"04.gif"));
icon[4] = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"05.gif"));
icon[5] = new ImageIcon(netbar.NotepadConstruct.class.getResource(
"06.gif"));
}
public void go() {
animator = new javax.swing.Timer(22 + 22 + 22, this);
animator.start();
}
public void paint(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
for (int i = 0; i < numImages; i++) {
if (x[i] > 3 * i) {
nudge(i);
squish(g, icon[i], xh[i], yh[i], scale[i]);
} else {
x[i] += .05;
y[i] += .05;
}
}
}
Random rand = new Random();
public void nudge(int i) {
x[i] += (double) rand.nextInt(1000) / 8756;
y[i] += (double) rand.nextInt(1000) / 5432;
int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10);
scale[i] = (double) tmpScale / 10;
int nudgeX = (int) (((double) getWidth() / 2) * .8);
int nudgeY = (int) (((double) getHeight() / 2) * .60);
xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX;
yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY;
}
public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
if (isVisible()) {
g.drawImage(icon.getImage(), x, y,
(int) (icon.getIconWidth() * scale),
(int) (icon.getIconHeight() * scale),
this);
}
}
public void actionPerformed(ActionEvent actionEvent) {
if (isVisible()) {
repaint();
} else {
animator.stop();
}
}
}
public class NetBar {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
final SwingProgressBarExample it = new SwingProgressBarExample();
it.add(it);
it.close();
NotepadConstruct bar = new NotepadConstruct();
bar.createConnection();
bar.Flogin();
bar.fmain();
bar.fstart();
bar.fend();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -