该用户从未签到
|
- import javax.swing.*;4 g: a3 R, p- ~" t
- 8 e, d/ X& l- r1 ]+ V0 _" C/ D
- import java.awt.*;
2 ?' A, c$ l6 K* \# T \6 [ - import java.awt.event.*;
- H5 @1 U8 C" p) o" B$ ` - import java.awt.image.ImageObserver;
& {) L8 S1 v7 x- G, W; y - 7 }4 s* B) T8 A3 _/ ^4 _
- public class Welcome extends JFrame{
7 U q" h' l. Y) ]; I - /**
# y; k( u+ ?3 [: u: D - *
1 u; n/ Y+ l& a A/ X7 C - */
[ l' t/ `3 T! u6 U H n! K - private static final long serialVersionUID = 1L;; S1 F O: A! p0 {& I! u$ z9 g
- /**
, R( ?$ `9 A/ c2 @ - *
+ e" I/ m# [: P7 Z - */# k+ d5 Q+ ], E+ F3 [. \2 \' U
- private JButton JB,JB1,JB2,JB3;; m5 L9 C% E- N: e
- private JLabel JL;
) i9 X" m. n/ y+ S - private Image img;
5 d8 F2 T: \0 S - private Toolkit tool;
. [; W- @, C3 K3 `- G$ y
5 b# Z/ _0 H8 J- l1 r( a/ C) P& |- Welcome(){' ~6 v8 ^5 ]6 Q Y
- super("欢迎来到科帮网");( ?9 W% ?+ g- K! ?5 g+ A
- setSize(600,500);: r0 k9 {, p( J' e' F! {: Y
- setLocation(250, 150);
& E/ x B4 K& V! J# \7 G - Container container = getContentPane();
a0 o8 j/ b8 q- C6 G1 ~* r4 R - tool = getToolkit();4 U* I% o+ n1 K' j/ R7 F9 z3 S0 i
- container.setLayout(null);
( Y+ q- d2 ^0 G- i0 W! J: W - $ p& z- A( X) D5 e: [ a P1 z
- JB = new JButton("查询学校景点信息");9 [0 l# z, W% |: z; J. p
- JB1 = new JButton("查询2景点间的最短距离");
& W/ X8 e7 r5 d9 _- ^$ e9 f - JB2 = new JButton("查询旅游路线");
9 x% m' H; m# E U; H% e1 v - JB3 = new JButton("退出");
, `4 q; a5 h4 ^; C0 U - JL = new JLabel("欢迎使用校园导游咨询系统");
4 G/ V: `: R' f& r+ X5 H! x - img = tool.getImage("E://School.jpg");
( Y! f" X, o; C6 t; [/ r% a* ^ - ! A+ }, H7 S( v
- JB.addActionListener(new MyMonitor());
{8 H i# V2 }# C- A3 g - JB1.addActionListener(new MyMonitor());
9 ^+ M4 m; J! U4 L0 y- @" X - JB2.addActionListener(new MyMonitor());
$ p' a' @( y/ t - JB3.addActionListener((new MyMonitor()));( Q* @! J+ l+ m
! y6 c1 o) V3 L8 Z+ t- JL.setBounds(180, 20, 300, 40);
4 }/ k/ E# f8 f& P0 V& ?2 a - JB.setBounds(200, 60, 200, 30);
3 _$ T% b$ y- ~* Q9 x( ? - JB1.setBounds(200, 100, 200, 30);/ z3 d9 y8 D- Q* m! O, F; l( ]+ ~
- JB2.setBounds(200, 140,200, 30);/ y9 `" e9 ]) \5 y5 e. N, @5 O j9 f
- JB3.setBounds(500, 400, 90, 30);
, V l n" ~* ^ - , g/ |3 q. A5 m2 y2 K" j3 \
- 4 t& _. g0 j2 F
- container.add(JB);
* U# n0 A# Z+ v: K1 T2 B0 }7 f - container.add(JB1);
( k4 B2 X3 K- S1 O* p - container.add(JB2);
/ N6 Y/ F/ S; i" L' d- U# ^ - container.add(JB3);; x8 s2 @# z. h, f5 m2 w2 J2 s; k
- container.add(JL);: n, a% o u% L
- ! V- ?: N: W+ l! \3 e; H1 A- l
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);! ~9 D' m" Z2 ]4 r: x1 C Z; L
- setVisible(true);$ T2 q7 k; t8 A3 @; Q
- 6 |3 k% }* `, Z: w% W
- }
/ |2 q c. s' w5 b9 a - ! G6 S: O- }& k- o+ W
- private class MyMonitor implements ActionListener{
# r( x7 D3 f) D! t, h
7 a' M) r4 J& o2 c5 e# u- public void actionPerformed(ActionEvent e) {/ Q. S( n, @* j
- if(e.getSource()==JB){2 v1 z8 l7 b$ x/ @/ S1 B
- new MyGraphy();
) q& k/ ~6 ^) m1 z, h5 q7 Y8 ? - setVisible(false);' J E R P& M8 I$ o) s
- }
) H; b! f3 R" L2 p# Y2 v; f t - if(e.getSource()==JB1){
, H u( I+ M4 k$ v2 t3 p# S1 } - new ShowLength();
- `3 C9 b1 T! U - setVisible(false);3 ~$ ^' T+ d: \
- }
. ?5 D& ~2 z/ c1 g1 W4 p3 z - if(e.getSource()==JB2){
4 o* a+ p' q1 B - new ShowView();
! R1 u$ H! V0 {9 `; F - setVisible(false);
6 ]! E, v0 j& n1 S4 q1 f$ k5 p - }
' M1 U0 I! p. m' M7 k) h1 j
6 D* E/ X2 h7 D- m- if(e.getSource()==JB3){5 B" A3 s g% }8 r7 V( W4 p( A. X8 T l0 e
- System.exit(0);2 D/ n5 `: C8 I2 k! K' h. O
- }7 q9 Z4 w2 s2 y
- , K2 n/ j( r- c1 y! q; j
- }& o/ m. G3 l3 z4 z
' n- b: G5 | Q* v7 z: A( S- }8 E0 |7 J9 \8 u, R! L$ }
/ m9 f& \, G# C7 N- public void paint(Graphics g){
8 ?6 H2 v, v; K U - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
# \4 n/ i+ x) n0 j' ?0 F/ |8 L
2 c9 Q( A1 F& [, r% w, m- }
* A& ^' R& }+ O7 A. A' U w - # S& A+ a; s4 O0 i' K$ M. |! F1 ]7 S
! C/ b7 W; O5 U' _; j4 S- public static void main(String[] args) {2 ?5 U* t+ d3 V; q$ f
- new Welcome();0 |( u" N1 _; D6 V
- }
% q: ~0 W% s# M - }+ g. j. x$ X9 Q! F
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
2 |$ A- ?: t; v+ L$ G |
|