|
该用户从未签到
|
- import javax.swing.*;
% z3 W1 C R, }$ A- v3 \4 D - 5 D$ g) j5 v. R# m- P- D) L' ^
- import java.awt.*;
: M6 n" N1 j) p) [; N( Q - import java.awt.event.*;
! n. o. ^. t0 `& t; s. k! L) e9 H - import java.awt.image.ImageObserver;
* c* |" V) Q7 W. H! _7 V; m' d. R
/ r& w8 z+ F; q. o* W C2 I- public class Welcome extends JFrame{8 \* u7 m- {" k( x0 g8 F7 k: B
- /**
& W( e& b0 M1 `) \& @ - *
& m4 T2 _$ c3 Z" a# E% O$ U - */1 D0 z/ H4 R# i( Z
- private static final long serialVersionUID = 1L;3 v. k3 P# l: L4 s( M& O# V( ^
- /**" I8 R* b9 @2 V/ [( u9 c( Y. E3 U
- *
8 m/ b1 ?* t9 s4 m/ z2 O3 g2 S - */
9 J- Z6 L# P+ ^ - private JButton JB,JB1,JB2,JB3;' r% p7 L' Y' I6 t" v: ~
- private JLabel JL;! e7 i% W9 M8 e$ E' e" J9 q3 ?9 `
- private Image img;
( l+ h2 B! y& \' y8 C8 v$ u+ T - private Toolkit tool;
8 I5 J# u {5 _/ `+ }& B
* x; m' b' |6 ?: }& N% A- Welcome(){! {8 N) n9 m2 Q4 c! C
- super("欢迎来到科帮网");
! a8 M. [" L. @+ q. F - setSize(600,500);
# Q* \# R+ |4 C1 f, G" C3 Y: ?5 A - setLocation(250, 150);6 [5 l2 r. D( N4 [. ^! }
- Container container = getContentPane();1 S( b" i# U: z, j A5 L
- tool = getToolkit();
9 E3 S5 _# H# l& C4 h& h, Q - container.setLayout(null);
# H; h2 U( R& `5 e% ~: R! E" f
' T- f, b9 @% }- JB = new JButton("查询学校景点信息");
6 l" }5 }7 P! E3 j6 b; T: Y" t5 E' h - JB1 = new JButton("查询2景点间的最短距离");! i9 `! f' l1 E6 o1 y
- JB2 = new JButton("查询旅游路线");
, d- B) z1 i0 y7 |0 r - JB3 = new JButton("退出");( o1 t* l6 j& o2 P
- JL = new JLabel("欢迎使用校园导游咨询系统");
1 y9 T% [+ F5 ?$ Z2 j$ M - img = tool.getImage("E://School.jpg");
5 T! R2 C, W$ @ - % i# O2 j/ r; V( `1 X' u) C# I, c
- JB.addActionListener(new MyMonitor());; c# H$ ?; m& S) k
- JB1.addActionListener(new MyMonitor());
B. c/ P Q/ d! q# Y8 a! | - JB2.addActionListener(new MyMonitor());: c% e F) Z. d8 Y
- JB3.addActionListener((new MyMonitor()));
& Y! I* y! E" t) ^4 i* B$ G6 a. T5 g
0 \) V. I/ n: K% n q4 A; Y5 J- JL.setBounds(180, 20, 300, 40);; b0 @( Y& J9 N8 B- x
- JB.setBounds(200, 60, 200, 30);# E: j X1 S( T6 x' x& F6 K, z5 h3 k
- JB1.setBounds(200, 100, 200, 30);
" B( D4 L. H- l. y/ f+ s# ? - JB2.setBounds(200, 140,200, 30);
% V a( m9 W; i - JB3.setBounds(500, 400, 90, 30);
* c& B: E/ c. s2 }* k) `0 p
) ?8 {$ W3 {" t9 C5 @! \) J8 @2 H: e- ' E8 v3 \% E5 [6 g a
- container.add(JB);
* l4 {4 c" o2 R3 d6 M - container.add(JB1);1 u& N8 P5 y1 c/ {0 s* _
- container.add(JB2);- @& K9 R+ ^; [
- container.add(JB3);( f0 M, x7 L# P) R
- container.add(JL);
) K q6 a* y( D5 U) x! w6 M5 ^
7 \ s( l0 _. Y6 T) H- b- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
7 x5 L1 c' ?. ~! u( c - setVisible(true);
7 D9 f z9 m( P
% |7 \- P5 z* L* {0 r) T! `- }. V9 `* Q+ l5 g I& e: q
" T, G. h8 Y, n8 D5 m, `- private class MyMonitor implements ActionListener{
# X9 N" }4 T7 T7 l
4 c, |' B l9 _- public void actionPerformed(ActionEvent e) {
5 s9 O$ Q' k- `# }3 B2 N3 z5 v4 ]' ]3 R4 | - if(e.getSource()==JB){
0 Z2 L( S- b* ]3 D* M - new MyGraphy();/ x2 v! ]6 [* E7 O
- setVisible(false);
1 M+ X- y+ _7 E! F& x - }7 t P6 [+ P/ f, C* C* a1 L. U e. ^
- if(e.getSource()==JB1){
: t. a3 V. P$ @& A0 [ - new ShowLength();
/ u) ^: N; Y: t5 m S! D - setVisible(false);
3 ^$ J! l* t- C3 H( ~2 x - }! u# e) p/ p) E
- if(e.getSource()==JB2){
P9 ^8 c' s, D8 Q0 {! }9 @ - new ShowView();
& V' {' u& d( t1 N - setVisible(false);( `7 L8 ?" f) b! u4 M* K, `
- }- s& I# G8 c2 b9 H0 v
- 8 x. F h. R& \ {9 u4 T6 u+ p, [
- if(e.getSource()==JB3){$ o5 {5 X8 ~, S5 y' b( T) N. f r
- System.exit(0);7 x) _& {3 p5 c4 p5 W% r4 C
- }
2 n; a+ ^' X9 g' m+ R
# \ U4 V+ V8 F3 b% r, X- }1 L' E, L2 ^0 A3 E! g
. H) ^' y: |- O$ g- }. k$ ^7 e! Y5 Z! l) y
- ' h7 Z+ f+ ]# F! U: Y# D
- public void paint(Graphics g){
4 R3 a4 |) T! B$ R7 J' f, w- i& Z - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);4 _4 p6 }5 N3 J- X( K# _ _
- : n8 K: t+ F! E" [2 u% x
- }
2 w$ i# ^* }, ^$ a - o' L( a5 _ ~: o
- % i! N; r# y3 J) Q J( F- v$ Q0 w1 [
- public static void main(String[] args) {8 p# Z% b6 ~* o( ]3 ]; s
- new Welcome();4 T# W" I6 V, }5 F8 `% S* a# V
- }
! x( F' d z# v2 n$ ]% d - }( {# `. F7 A q6 ]' Y* q. @% J
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g). j4 u- o2 S8 i+ a8 ~) B$ P
|
|