该用户从未签到
|
- import javax.swing.*;% Z9 v- x5 c. o' {# G
- - i" G5 g6 o# x$ i8 B
- import java.awt.*;2 h' N) _0 L* s0 S+ m; C4 F
- import java.awt.event.*;
$ ~7 F0 v+ _- k7 w8 f+ ^+ E4 b - import java.awt.image.ImageObserver;$ g6 W3 o- K- u* x# }& _
- 2 `/ ]( y! [, t9 U& J% }/ \
- public class Welcome extends JFrame{
! |8 W& N$ I8 s$ G. F - /**) z7 y; B. G+ G. f9 {9 ?; i3 N
- * : g9 y' r* t( a# q# [
- */
: F9 r4 H+ O4 S4 z7 b7 P9 n4 q" V/ R - private static final long serialVersionUID = 1L;: G" k' C2 v/ j5 G
- /**
" ]% {! m4 {3 B% B9 \$ k - * : X+ U) U7 G9 c4 D9 e- C
- */' e5 ^& Q* M& ~' R, I# i2 |8 M
- private JButton JB,JB1,JB2,JB3;
$ i) t& ]* ` }5 E' K - private JLabel JL;
) f5 P* {( Z5 W5 E/ v - private Image img;
. n$ e2 n b) ~% U - private Toolkit tool;
% x' W: Y4 k M6 s5 a; V* @- u - 4 ?% x) U) Y/ j; h0 y9 C/ m" d
- Welcome(){* j! W8 m y3 ^" e O, @
- super("欢迎来到科帮网");
3 I9 T7 Q1 n3 ~6 C2 C$ Z. q( [$ H7 [ - setSize(600,500);
% ~6 `1 c) q3 i. @8 Y - setLocation(250, 150);
9 k& d+ z. C1 F - Container container = getContentPane();" H1 A f) `1 u, z* m) p
- tool = getToolkit();
& Q9 L1 \$ T' |" @* ? ? - container.setLayout(null);
0 R8 D5 Y4 E9 E% O
7 o+ \$ c8 R; K% V b- JB = new JButton("查询学校景点信息");
# `, `" d3 P/ u9 R% Y! J# P' Q( } - JB1 = new JButton("查询2景点间的最短距离");
6 @" S9 H" Q0 _1 D" Q - JB2 = new JButton("查询旅游路线");" M" K- `1 [& S, X% m& U
- JB3 = new JButton("退出");! B& a7 }" j* B2 r: j
- JL = new JLabel("欢迎使用校园导游咨询系统");
9 Y8 Z0 C- ~: p - img = tool.getImage("E://School.jpg");
4 w" a( j3 [3 U; u - 1 K* U7 z: f$ `
- JB.addActionListener(new MyMonitor());
. y! s. y- H) O - JB1.addActionListener(new MyMonitor());
/ I* G. {3 d9 t/ \- \ - JB2.addActionListener(new MyMonitor());
! e2 h/ s. N- F9 x5 R$ |$ v - JB3.addActionListener((new MyMonitor()));" W q2 b0 G! t& B
" t4 ?/ j2 O% J% Z$ K- JL.setBounds(180, 20, 300, 40);0 L$ X* {0 X% K
- JB.setBounds(200, 60, 200, 30);
" h' g/ x$ u! n - JB1.setBounds(200, 100, 200, 30);5 C5 L5 S7 J! `; S
- JB2.setBounds(200, 140,200, 30);
% M5 v6 h9 W: H - JB3.setBounds(500, 400, 90, 30);
" }8 t1 B( a" [
' w4 }3 j9 h( s0 i1 v6 p
2 T7 f. W- i! o A ], v2 s) f- container.add(JB);' @! b2 f6 h# U- w/ M0 S
- container.add(JB1); d$ P% e# Y/ G: a' ?3 c0 H8 q
- container.add(JB2);
7 [9 g( ^0 h; j) V - container.add(JB3);
+ t6 m* ]% s. O - container.add(JL);
* C4 s0 y0 n0 D) `) }! y2 p4 D
4 @$ ?. P6 [( O0 Z4 C- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);2 K3 ?: E+ f& q' k: w
- setVisible(true);
4 M8 i0 }/ o! t5 b
& j: W2 t$ F/ Q. Z: o8 X- }# m; I& @3 C1 m- ?/ p$ X# [( q% j, f
9 A2 f0 |1 R) o$ {6 S; O/ Z- private class MyMonitor implements ActionListener{
) s/ c) }+ M) u; @( S& f
6 ]- X& N# ?* r- public void actionPerformed(ActionEvent e) {+ n7 J% \% P, [( e% B
- if(e.getSource()==JB){' R9 _. j) I2 D2 h' T# }
- new MyGraphy();8 S Z) c* r6 w. e4 z6 `0 ~) }
- setVisible(false);
, l6 H) G/ B9 w+ S: J, N0 D - }9 ?4 M, d6 |0 y& v$ e: n; K# `
- if(e.getSource()==JB1){
" U2 C* D% }4 Y- c) }5 o - new ShowLength();( J0 A8 z. o$ m' J/ O7 ?2 a1 X
- setVisible(false);' T4 o' y' ]* A' G. M
- }
~6 D& M3 b& f. L) N7 b3 ]( D - if(e.getSource()==JB2){
7 }; W0 L9 G" K* j - new ShowView();
& i4 u1 r5 |+ N, z - setVisible(false);8 n5 B$ _8 Q0 W0 }+ W( |0 M
- }
. T5 j: C$ m& b$ `, _( l - , f. q8 \! }2 h% P5 y+ Z5 A$ M5 B
- if(e.getSource()==JB3){6 t) s0 M n: L9 A# U y+ n
- System.exit(0);* I, R, S, a6 m% h( @
- }9 c3 |* `+ }( z N
/ N J2 s, r, n2 m* l( @+ V1 `9 [- }: P2 }% h+ Y; T% t% P# u
t9 O( p( Q: A& ~* A$ g4 V5 g3 _- }$ m+ p7 ?8 Y d$ L$ j
- 9 k' U. M( G. r0 ]1 u
- public void paint(Graphics g){
]9 b E7 r& v A - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
, T5 w& p2 }9 F4 i3 V% M
6 ]9 Y* C: r1 J# ]- }
* v: A8 O0 ~% O' X4 X0 M
2 a. |" I- E1 Z, o- 4 S7 _" d( ~/ d0 F8 H" P9 \
- public static void main(String[] args) {% |+ `; U0 V3 o, W, x+ a
- new Welcome();
z/ ]/ @8 s) S8 h8 z - }
% [0 l6 W( d0 s$ i - }
6 o* W& O! ^5 B( |1 Y- @
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)! Z8 ~* a, {1 n1 a' Z& X
|
|