该用户从未签到
|
- import javax.swing.*;
4 N. l# Q$ L; ?# | - ( \6 ]- T2 S0 P0 i6 n
- import java.awt.*;
- Q7 C. z$ P* I6 Z l - import java.awt.event.*;
0 l' u, N m2 i8 w8 q - import java.awt.image.ImageObserver;
) L: [/ q: F" U) `) V; G* s - 3 K; C) N: j2 A
- public class Welcome extends JFrame{ h. ]7 ?' ~# r9 }0 Q6 t
- /**, M( t, _9 {- ?4 z+ `+ R. y6 H
- * / G' U: B9 |( ^& {
- */+ @! I* D- B, |: d4 F
- private static final long serialVersionUID = 1L;
: j. ]. A3 K4 y, { - /**$ W% n3 _$ M" ?& f' w
- *
3 Y9 v9 m* i2 | - */. a! U3 T; l2 _6 k2 j
- private JButton JB,JB1,JB2,JB3;
2 V' P2 D E5 r7 @# d - private JLabel JL;
8 Y9 ]; z2 b) r2 a8 n, L - private Image img;+ w# c6 \" N7 Q* _3 P$ B+ x+ ~) Z, t7 V
- private Toolkit tool;/ Z0 d. ?+ L9 L
- f! }% g) V* o- Welcome(){) d5 @) I' R- q' U& D- `% {. S
- super("欢迎来到科帮网");
" y3 ~5 ^! h& ^. U- h - setSize(600,500);
7 V1 @- Z; Q6 Q# j, |& d {( `* S - setLocation(250, 150);
4 ~: y q* Z- q' P* E - Container container = getContentPane();
5 O1 F% d: ?2 y0 k4 S - tool = getToolkit();1 Z# e8 K2 S, h
- container.setLayout(null);9 c3 k, M6 P# C& \+ }
: l8 T. O- M) y* X* M3 G- JB = new JButton("查询学校景点信息");) V" t9 C, D+ g: a' M0 t
- JB1 = new JButton("查询2景点间的最短距离");# K" H. v2 ]3 J/ b0 p- `: D+ x
- JB2 = new JButton("查询旅游路线");8 n6 P* S" {9 z1 S9 e2 e
- JB3 = new JButton("退出");1 G5 U. O, Q' {$ P9 M
- JL = new JLabel("欢迎使用校园导游咨询系统");1 U$ Z- ^5 H l
- img = tool.getImage("E://School.jpg");
5 j4 ?6 F3 r2 y. X- Y/ r
$ @& Q5 S+ W6 H# _1 [3 B" B' Q2 T- JB.addActionListener(new MyMonitor());( P) u6 G, u, K" Y7 B6 Y3 f
- JB1.addActionListener(new MyMonitor());
" i6 C F4 ~6 h* M5 l }2 V9 o - JB2.addActionListener(new MyMonitor());" D/ D3 N* h( V, {. s( D" o7 D' E6 G
- JB3.addActionListener((new MyMonitor()));
/ ]- N4 m& r/ o - . L& C0 }2 x4 o$ y5 s5 `/ \) R) D
- JL.setBounds(180, 20, 300, 40);9 |+ g, a$ K$ [: E; Q
- JB.setBounds(200, 60, 200, 30);
" A7 {. [* B& m5 x - JB1.setBounds(200, 100, 200, 30);
6 [' w' a7 [2 R- a; r. q - JB2.setBounds(200, 140,200, 30);' ? t, s6 l/ a
- JB3.setBounds(500, 400, 90, 30); N6 n) P% u: f- R* V
- 1 G& E& Y4 p- [- `0 r# q9 I
- ' T4 W) X0 k M2 @" o* r
- container.add(JB);% O; p, z* @6 E7 r$ a
- container.add(JB1);
; v+ J2 A: w$ h5 Y! c0 H) }+ l - container.add(JB2);
1 O# r# X# `& A3 E' \ - container.add(JB3); C3 C# l% n+ U Q z) P
- container.add(JL);
3 B5 @& K$ g; x
1 U% O5 W0 ?4 J8 o) D C; ]" {* [- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2 l! A; n1 z1 t$ N/ x. h' { - setVisible(true);
( [# m# J) q: S& S5 N1 c* ~
3 y5 O" Q# q( N4 K6 K, V0 B3 S- }9 Z' ]8 S. K$ Q5 m5 C) e
- 5 J" D) H8 b& y9 N3 X: v
- private class MyMonitor implements ActionListener{5 D& |5 B7 k J' j2 A p% ^
$ c( b2 J) a" k+ E' z! P$ i- public void actionPerformed(ActionEvent e) {& b" Y# L0 Q0 y6 Z5 G- \9 u. [" ?
- if(e.getSource()==JB){
. M* Z* ]. D8 E - new MyGraphy();6 z5 F, A; f- n
- setVisible(false);/ s% r+ E8 D4 f8 E1 W" b8 c
- }0 z" b/ p) F- p# k" C; Y% o! P0 [
- if(e.getSource()==JB1){
5 M; l3 X; @2 k& \& _" e8 t - new ShowLength();- @: L3 m- t! q) [8 c
- setVisible(false);* e% T) N9 [7 ?6 ^6 U
- }- {/ R6 y0 B' [ ~
- if(e.getSource()==JB2){2 `, z, l; a3 ~& J2 X! O
- new ShowView();
6 B% s- N/ M& g9 y/ j0 P4 \ - setVisible(false);$ K. e+ R8 R! Z* u$ V# {2 g3 y5 N
- }3 v; T* |7 x2 c" e% k8 h
5 U7 @# _' b1 f* |% V9 m9 z6 D- if(e.getSource()==JB3){
3 x& @: s3 r3 y. d. g - System.exit(0);# x$ @, c8 K. z+ t8 m4 I
- }
' K1 f5 L' B9 E% p# F+ ]! d# i, ? - 6 I3 w& }: Y. Q: u S
- }
. [. f- F9 T; @) S8 d5 z! z" L# t - # l% b6 F& d" o, W; s2 V9 N2 `: \
- }
3 ^! C w' Q9 M( o - ' n+ P8 v, F) g# y$ d2 A5 ]; ~
- public void paint(Graphics g){
, p5 F6 j) ^7 r s0 ~' e$ N - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
. ]8 J; A @6 X9 P, B1 ^
6 E' X% g Q# p+ k* Z- }
# ?. {7 ?4 m! i/ d8 ]+ I0 K1 k - 6 n% w' x+ i; L9 l' s
1 n, |* N X8 Y- b8 l$ N- public static void main(String[] args) {
9 y9 {) v; X7 }( ?1 D1 q: y - new Welcome();
1 G7 }4 ~( u N$ p - }4 ~+ `+ o9 P# W
- }
. R0 _1 f |0 O3 `8 j F) k
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)7 _) U: h( \3 d/ Z
|
|