|
该用户从未签到
|
- import javax.swing.*;3 K% _* [+ p7 F
- 0 Y2 |/ W0 [: s. j9 Z( D8 s
- import java.awt.*;
" a( S2 f5 _! o( k4 T - import java.awt.event.*;
2 h8 Z1 J9 y6 E5 v! L! c$ r4 z - import java.awt.image.ImageObserver;
d6 a$ f. [9 \, f - 5 E& o# ?9 Y- v1 B( K7 A7 W7 a
- public class Welcome extends JFrame{
. b: J9 A1 t. [& f; A# n0 L - /**
2 j3 n$ W% Z/ g - *
4 r. \+ B/ K$ n0 h# _5 U+ ]. ]/ L - */
8 J+ n- V1 h# j' h7 G8 s - private static final long serialVersionUID = 1L;$ J( Z9 V7 k ~* `
- /**
3 } t5 i2 y( I* `4 J: z9 f i - *
" M: L# P# Y [+ f% f$ R) ] - */
! E0 k. Y+ i, j9 |- Z; i - private JButton JB,JB1,JB2,JB3;, ~# A8 P' }* s/ Z
- private JLabel JL;) g5 Y# |2 ~8 V+ h
- private Image img;
: e& }, L, l& R* @, k5 g - private Toolkit tool;
% e2 }5 D8 P' \; s$ t
; {4 e8 g/ p7 a- Welcome(){. ?) W/ s3 s# R8 J1 z1 p
- super("欢迎来到科帮网");
0 M$ g& I( r$ \# C2 ]' P - setSize(600,500);0 q) C" R7 r6 \
- setLocation(250, 150);+ E( j+ S0 M' |
- Container container = getContentPane();; G7 T; _; L& S. I- I9 q
- tool = getToolkit();5 O7 n- d3 K9 e
- container.setLayout(null);
& C) o! Z0 L9 f2 D% v ^3 G - 1 \! ^$ }# z. @* V
- JB = new JButton("查询学校景点信息");+ n" ^' f8 o9 z: A. Z
- JB1 = new JButton("查询2景点间的最短距离");2 W. ?- [' p' Q# W: Q; F6 G. `
- JB2 = new JButton("查询旅游路线");" F3 k. c* a- D0 {9 n
- JB3 = new JButton("退出");
, @- F8 l- D$ }7 D - JL = new JLabel("欢迎使用校园导游咨询系统");
% ^- |- h+ G8 c' p6 s - img = tool.getImage("E://School.jpg");% Q' D$ v/ D5 l! `
- ( k/ f* H; @ O' B
- JB.addActionListener(new MyMonitor());
5 x! L1 J' p- d6 t. p" j - JB1.addActionListener(new MyMonitor());# R. d9 Z( o4 }# J4 v" ] I R
- JB2.addActionListener(new MyMonitor());, p5 Z$ E8 a' L, `/ x' a
- JB3.addActionListener((new MyMonitor()));/ l1 V# x; X* E' a" }
- 2 {$ v4 U7 D/ \
- JL.setBounds(180, 20, 300, 40);
! Y# v6 O$ u9 Y' Y% U1 L - JB.setBounds(200, 60, 200, 30);
; Q' L' p( D4 H/ ]) ?0 B - JB1.setBounds(200, 100, 200, 30);$ t0 M+ t1 s X, C
- JB2.setBounds(200, 140,200, 30);# [( X7 _( T0 h* o! n0 Z3 Q
- JB3.setBounds(500, 400, 90, 30);
# c+ q- R2 R+ L c4 K- n: L - 9 O1 o2 h2 U; \6 i6 r* R# @
7 j7 F& |; ?; k- o' l+ v9 [. X: y- container.add(JB);
- {( m3 q% m p+ K - container.add(JB1);
) I3 j' d; ~8 C4 j - container.add(JB2);
- ~/ J. Z/ h, D, L- D - container.add(JB3);
' f q. F; `2 t6 r2 d4 B+ G - container.add(JL);
& f6 t5 F! M t' I, M e - - u6 K) x8 |& ]
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9 Z* G3 p( _" }7 e( P" Z( T9 W - setVisible(true);
, M/ M% L( G! W
3 J& C9 O4 |: K: K' d! u; d% A# E- }; F& m4 Q% s; {; s! {. } }* |+ l. S
- 7 O- c8 G- Q o: \
- private class MyMonitor implements ActionListener{$ o% V8 j- d! w
3 n: y5 J9 |* z+ u. ^- public void actionPerformed(ActionEvent e) {8 U3 d$ Y* R3 c! o8 i
- if(e.getSource()==JB){. ~& x" j! w" }5 F
- new MyGraphy();/ B) t! P. g/ T# O# E/ H
- setVisible(false);
6 z: h' s- W! L8 p0 S - }
: o: Q7 H" a, Z/ q/ ^5 T2 ~. N - if(e.getSource()==JB1){5 r1 C0 Z# d6 @# {% l8 f
- new ShowLength();
: U1 A' D. G+ @# o - setVisible(false);: B) u, _' Q9 L8 w0 ]4 o
- }5 Y% U/ } k2 p9 p% R: f% w4 _
- if(e.getSource()==JB2){
. a9 m: `6 e# A - new ShowView();
' H8 r& s D& _; \; C - setVisible(false);
4 O+ g4 q: y' J8 k( Y/ w5 W* [ - }
# A/ j- X4 s! B) @( P9 I7 Z3 X8 ~ - 3 I6 ? y' c% b( [6 G' `
- if(e.getSource()==JB3){7 _' l. R5 S4 g- r8 B
- System.exit(0);; z0 }# R- t& o, X4 c* d
- }: X; @: p" n8 r% Q
- . h- `( x# ]% E" o! O& T
- }4 y% }' b5 h9 W$ p
- , q3 W. l, s F8 f2 r
- }
4 g2 }$ I, F# ^# @$ c - 7 a! h. S- u7 P" H3 t0 M3 _
- public void paint(Graphics g){
1 {' w' Z6 M& m, b l% [$ o; g+ O - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);7 d6 [' b S. y
- 4 R0 u$ O3 n& H% ^4 j8 K' O8 @- b
- }, x& r% n1 X, T Q; i7 h
: f( _& V) ^. F7 d, o- - U2 L% @7 |$ T
- public static void main(String[] args) {( s4 [; P% E% Z6 {9 L: [
- new Welcome();
# E( u: q( s/ Y% l$ H - }9 M4 M4 p& l7 N
- }
# f4 l9 L$ g5 w! O0 o
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
U4 {- ~" [; V; m" B3 X# M5 F% z |
|