该用户从未签到
|
- import javax.swing.*;
$ E9 l2 B; {3 u' @ - 1 L/ T; y7 e% z. z
- import java.awt.*;
4 Y' g' e/ D' d9 d8 ~/ t5 Y, w - import java.awt.event.*;% }3 }/ r' U' p' p' b1 F* S9 x
- import java.awt.image.ImageObserver;
1 m- N1 [* u8 J: t7 u0 ]* [5 ^
' ^9 K, w' q) x; F) u, C- public class Welcome extends JFrame{
% Q* t1 i, Z d0 O' V - /**
. I+ {1 L) J4 M( K0 S. ] - * 6 Y9 E* w2 \" i4 p- ~ G* B
- *// u& G: v. \& H2 y: c' o8 G
- private static final long serialVersionUID = 1L;: C0 ~* T/ Q( |9 [
- /**) W5 `# y C# |9 F, L: ^5 ]% p) m
- *
7 Q( o7 s- P; y - */
+ ^, C% v ^; W4 }5 f, w- A - private JButton JB,JB1,JB2,JB3;2 W$ x4 `9 b4 b! \! A
- private JLabel JL;: O2 k$ N' T6 y
- private Image img;. l6 @/ h& e: F5 S* \+ z0 g. s
- private Toolkit tool;' s; }4 R b6 c2 d- k& @. Z
- ( S, q5 Q3 D' g1 _
- Welcome(){/ n4 f/ o% o4 S8 T1 s
- super("欢迎来到科帮网");
* ^3 S7 N! Y0 u5 C5 g; E) h4 S" ~ - setSize(600,500);* g9 V, ?6 \& z# D* f' [, g6 g
- setLocation(250, 150);
8 ]/ n8 M+ X4 U! }4 T9 c - Container container = getContentPane();3 l* K* v4 ^: |* q0 I
- tool = getToolkit();) X& T' j `/ R' g/ R |$ _
- container.setLayout(null);; j' P* J/ y7 u
' r6 K0 q6 h* U2 R- JB = new JButton("查询学校景点信息");& ~5 U0 a" R, P; M
- JB1 = new JButton("查询2景点间的最短距离");& x: r0 {2 R/ m; g0 Y: N
- JB2 = new JButton("查询旅游路线");
# ?- Q% N- c8 ?" ^( L- S' f# K: `- s - JB3 = new JButton("退出");
! l1 @9 b; v) E+ A' F9 S. t - JL = new JLabel("欢迎使用校园导游咨询系统");6 `1 n2 D5 j2 I" q* d4 a
- img = tool.getImage("E://School.jpg");
R. l9 H) L9 |3 |2 w) P
5 D* Z7 J( K: O' u, r( N; K% h7 w- JB.addActionListener(new MyMonitor());" `" L+ H. S) V/ d1 w
- JB1.addActionListener(new MyMonitor());
$ l4 ^3 N$ v) n( A6 s: E7 m% k - JB2.addActionListener(new MyMonitor());
0 y- c1 v4 r( s2 Q1 }: W3 f - JB3.addActionListener((new MyMonitor()));
1 b* a; H2 L$ H( E- G$ O* ~
# g8 t1 w- {' v$ q! O0 N- JL.setBounds(180, 20, 300, 40);5 Z. j* @+ T* C7 F$ m4 I. b
- JB.setBounds(200, 60, 200, 30);. ^ }, R* `; S# ]
- JB1.setBounds(200, 100, 200, 30);3 f9 s. \; O# Q" g9 X, y
- JB2.setBounds(200, 140,200, 30);# X9 I9 @8 C- h. o5 e$ N$ ?
- JB3.setBounds(500, 400, 90, 30);
- t0 N) |- }6 X( N# k - : m0 t) o8 |3 a5 q; ^
" H6 x- S, b! }/ e+ d5 Q. j- j- container.add(JB);
5 k0 E- Y4 I3 z6 d - container.add(JB1);; B* I. s( [5 c( J
- container.add(JB2);5 d* s, d5 w, }% N6 N8 ?
- container.add(JB3);2 b8 B. ^: R4 }) P
- container.add(JL);
6 m* {' p, e1 _) f: \4 f6 S4 E - 9 Q+ O% X5 m% ^) Y0 z% R/ F
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
! X8 m0 _- r! l4 ? - setVisible(true);/ D. A$ j. Y! W. r1 P7 i4 {
! A5 b( k ]3 \* `' J1 r- }
1 }: j5 h0 D2 i. Y5 ] - 4 f0 `& C- K' {/ n+ \" T2 ~
- private class MyMonitor implements ActionListener{) U: C0 x- s; q: k8 @. ~! w
- / Y) I+ ~% K" Y. p. o: w2 Y
- public void actionPerformed(ActionEvent e) {0 m/ X. }& j; f1 x
- if(e.getSource()==JB){ L! p5 M6 F6 L% O
- new MyGraphy();3 C( `( ^) F% v, Z% i' [
- setVisible(false);) E1 S* A/ A2 c
- }
E0 G% F5 G* K2 d1 ~ - if(e.getSource()==JB1){
3 E- A" V7 J, f4 k' r - new ShowLength();
* \' F$ ^; J+ [ - setVisible(false);
( i- K; j2 B* p2 a4 V) c/ V - }
# E" U# t) V( e1 O- W. V - if(e.getSource()==JB2){6 Y3 w; x1 R4 I M' f' y
- new ShowView();
) ~7 O* b2 g7 L* g1 }2 l. P - setVisible(false);9 ^, m; R, d# U: W4 r' @; e3 I
- }
( Q* a5 f P; w4 I. }, @4 j1 c5 F; | - 8 [7 u) h4 V2 E! p2 a
- if(e.getSource()==JB3){5 d4 y3 r3 O. a% Q
- System.exit(0);7 J d7 n& O" f; j
- }0 I8 K5 ]* A( K% @0 w
) {+ G" @2 [; S9 d' E8 H# s- O8 h- }
2 x1 a( F3 G4 |) o# G - . b+ h& z# H1 g+ h* y
- }7 R( _7 r1 u3 L( w- u X6 P
- J4 O: i$ M! K+ S( V2 f- public void paint(Graphics g){4 n: H, D+ R& U% A
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);6 S1 G: n' C+ ?5 F
2 @+ S( M& C/ f' Y8 p( a- }+ G# Q% P; C+ t$ _5 x/ Z
% r+ y* i% r8 k/ Y+ L; a% ^: Z- ' k; M$ z' O9 F& J2 i% G
- public static void main(String[] args) {0 L4 ^. ^" b J
- new Welcome();5 t0 \8 f9 E- E' V
- }+ @2 x) J+ Y& u' O; [
- }
2 M6 Z' Z5 @/ ^3 s( J! X5 K: A' l( M
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
R/ P R8 K( ~- w8 r- T: M |
|