该用户从未签到
|
- import javax.swing.*;
1 b9 l2 s. ~7 a4 E* T0 s
: \* r9 @, B$ I& v- import java.awt.*;
! w0 }" h5 ?7 N4 j* y - import java.awt.event.*;
0 z ~2 ]& Q# z! `# Y+ t - import java.awt.image.ImageObserver;
; r6 A8 w1 t# M/ V+ c
) K" Z' v! s2 G3 j2 v v- public class Welcome extends JFrame{
, J+ ~( I" e2 V' }2 a/ H1 _1 @/ p - /**: V8 I- j" H1 ?# m
- *
5 q3 e% C4 A+ t# B2 J - */
1 H5 n9 [6 |: u$ L9 ?/ C7 ~ - private static final long serialVersionUID = 1L;* t8 p0 L" {0 f5 c) b! O, b
- /**1 z7 G+ z- ?/ d- V8 `# _# ~
- * 7 U3 I; o' S7 |: z$ M
- */& `0 o3 B7 f% f- i; U4 o1 D6 [
- private JButton JB,JB1,JB2,JB3;
: L( G: R u8 d - private JLabel JL;: J2 g# j- k$ I
- private Image img;
( l! ~) c2 H: }5 Z - private Toolkit tool;9 U: }: M. @* W, {2 R
8 ?2 P/ f# p, h; A7 H0 N- Welcome(){1 x; q; f( t4 g) L F% N
- super("欢迎来到科帮网");
( ?7 z0 D' O/ T - setSize(600,500);
; }, q" A' L& d5 W8 D - setLocation(250, 150);
2 P5 x4 ?8 q/ W* ~& G - Container container = getContentPane();
5 p- O+ y2 ]6 R8 ^& X! p% ^ - tool = getToolkit();8 v# Y i1 D" |7 x
- container.setLayout(null);. b6 M! L* r8 A. I7 m6 e
' m. X- L" }0 v1 _. X3 }7 @ y! C8 v- JB = new JButton("查询学校景点信息");
) p8 _, G, Q! w- X- ~* n u. g - JB1 = new JButton("查询2景点间的最短距离");
& q( W; M. r" q - JB2 = new JButton("查询旅游路线");# v' ~% a9 ~6 Y! l; ~' [* k' w# b, H2 r
- JB3 = new JButton("退出");9 h( @# i8 u; h% C4 c, |
- JL = new JLabel("欢迎使用校园导游咨询系统");
' M+ s a3 z/ A) K/ i9 r - img = tool.getImage("E://School.jpg");* ~% v( }- b3 d* m5 l* M6 A" T3 A
6 O* N2 o" x6 Z) p- JB.addActionListener(new MyMonitor());
$ Y, H3 o8 B# r9 h5 R2 \- j0 ] - JB1.addActionListener(new MyMonitor());! \0 W& X) f. n" l" U$ `" w
- JB2.addActionListener(new MyMonitor());
& M. k9 e( v: o4 i9 W6 G! ~ - JB3.addActionListener((new MyMonitor()));
8 P1 R( I0 a3 m+ w8 B U - ( ]6 |0 w" P. W3 j$ O
- JL.setBounds(180, 20, 300, 40);
) C- p( {0 }. s9 }, k1 v - JB.setBounds(200, 60, 200, 30);' T. B4 g1 J4 E% B+ g
- JB1.setBounds(200, 100, 200, 30);" r3 E3 a5 H2 W! J
- JB2.setBounds(200, 140,200, 30);: b1 ~3 P* T: M6 b+ l
- JB3.setBounds(500, 400, 90, 30);
; l9 f6 a2 F0 P$ l( _
" x3 [) \' n* A( V& ?
# g6 d' i( C) c& U7 _+ Z- container.add(JB);+ @; V. r( f' }; R3 t, S
- container.add(JB1);
6 W; }: `& l" O9 H; p( X - container.add(JB2);& s9 [0 M6 _7 x
- container.add(JB3);
0 |0 P, h4 D1 d1 @$ C% K N - container.add(JL);
2 L- ~$ ?* o% @' Z9 v# Q
7 ~! T6 Q# i% O; M- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4 O# O( X4 p& }6 {: b
- setVisible(true);
$ y4 M# a. J& x% N+ d( p
( [5 [6 }1 K F/ R A- }
# ?# x% k# H( Y( G - 8 a3 y. I: g* Z, q E% p
- private class MyMonitor implements ActionListener{/ L! l2 Y6 Q4 E$ w) h0 v1 P
, b% p: g$ X& l- public void actionPerformed(ActionEvent e) {
/ n! }/ `7 I e- ]/ S* q - if(e.getSource()==JB){
# d8 _; \# @ [$ \8 S/ `5 f - new MyGraphy();
4 G, t; R( p& j9 b% z5 z5 t& T: h - setVisible(false);
2 F; k4 W( b; N: h" }1 [# [) [. t% W - }0 A4 Z$ P8 U2 t% _7 o6 p
- if(e.getSource()==JB1){) ]+ F. b& v# D
- new ShowLength();, g% g: m0 o& G7 @1 S, B
- setVisible(false);# {! w- X+ }0 @
- }
" f& k$ A r6 [4 a - if(e.getSource()==JB2){
" \$ m$ b8 W, D - new ShowView(); T0 ?/ I9 B8 x! }3 d
- setVisible(false);
& v& p& m& `( O - }
4 D# O ^& E0 {; J$ E' _$ m" b
2 o- z6 E* W, f5 ?" S- if(e.getSource()==JB3){! U% W4 B a/ N, W' I& m
- System.exit(0);
" [9 m0 b$ ]: T2 o; Y- e# K - }
: ~, X- }9 m6 _, y% `# o W - * b3 F ~7 c3 d* F7 J
- }
7 G6 [2 G' X: M - % r; U6 i( `. A4 M& A# {' s
- }
0 D; S( i: Z; @$ F% M - $ w3 d- i5 _1 y6 i8 `: H4 d
- public void paint(Graphics g){. N0 R/ `. n5 c1 b- w0 r6 f; \
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);$ c! v Z+ _# \$ @9 Z+ N4 @6 i9 Z0 _
6 @3 D2 U6 n. J& l- }
8 F+ h; O) w- q5 E e' X - 7 ^' G# K' V" w+ B
- 5 n$ E) p' J- M
- public static void main(String[] args) {3 L) I' ^3 _+ G! a
- new Welcome();
4 E1 L! B' R( t3 }+ @ - }. d2 P! E$ u) V( F# Y# j. `
- }$ k3 p$ ?* a% T4 i1 [3 L( B! X+ y; ~
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
: k0 d4 k, A4 {& V |
|