|
该用户从未签到
|
- import javax.swing.*;! j% a! D: @/ Y2 f+ G6 n: r
- ) _# {1 n8 `$ E9 N
- import java.awt.*;
! [9 z2 v$ v1 `% T. [* b - import java.awt.event.*;
4 f" w' n, D% W/ t% n - import java.awt.image.ImageObserver;2 z" u( w- W! E- L- L% G
- % D& x1 W& V, q7 R F: C5 Z
- public class Welcome extends JFrame{
8 P, |& P! j+ ?- S - /**
0 O% u1 j# l4 e+ f- [( C. s- m' x - *
* d. o" w3 R3 P - */
+ C) B1 B6 w; S E9 f8 Y* C+ U; w5 Y - private static final long serialVersionUID = 1L;1 w- I% B( B% Y# j- g
- /**( P+ ~: a/ T$ A
- * / a! L: R" X8 _; Y( W
- */
$ ^! w, d1 a) V' |* F - private JButton JB,JB1,JB2,JB3;
1 v) I: g& x/ J9 y! i; [. W - private JLabel JL;/ V# m+ b: p# a0 J$ N T; `' M/ _
- private Image img;' I0 D- o5 ]; P% p' V. X
- private Toolkit tool;3 i: H8 X; q1 ~- R6 a/ Y4 s
- - b1 n; g3 R. n- J$ g+ O
- Welcome(){
, l$ ~3 n+ l$ v& ]% G/ |( ~ - super("欢迎来到科帮网");! l$ W+ t; b6 s2 p$ u& r- h
- setSize(600,500);* @+ T5 ]# u) B
- setLocation(250, 150);
: g5 k/ S/ _* M$ h# H# r - Container container = getContentPane();
0 V9 m7 t0 M# j. t# f - tool = getToolkit();& S. T# t: ?. C! Q! `- V0 ~
- container.setLayout(null);
! X# c; u1 L5 X) |9 s
& ~: F$ X$ ~( B8 X; b- {- JB = new JButton("查询学校景点信息");
9 P! V- f! J5 W+ L' S - JB1 = new JButton("查询2景点间的最短距离");
) @5 d- W3 A/ S; s, Z( ~ - JB2 = new JButton("查询旅游路线");$ [& \. t m- m' y V4 Y0 N
- JB3 = new JButton("退出");
5 Y, m: x" P/ j& E4 d4 s - JL = new JLabel("欢迎使用校园导游咨询系统");
- q+ O% K8 H/ x' W - img = tool.getImage("E://School.jpg");1 Z% q7 z: |# Z4 l( f
/ L- Y9 e! T& x6 f- p R9 A- JB.addActionListener(new MyMonitor());4 T5 V @/ Z; `( l: ? A2 `6 w
- JB1.addActionListener(new MyMonitor());- O5 U2 ?2 s' o: R+ H2 d3 R
- JB2.addActionListener(new MyMonitor());9 u9 U+ X D0 p7 d5 C9 I9 V R4 o0 K9 j! A
- JB3.addActionListener((new MyMonitor()));
; ^1 F$ }6 p. a" j- l - / v }7 v& t$ \* N% ?' Y
- JL.setBounds(180, 20, 300, 40);! p$ o. T/ L: \, b1 b, q( @1 ]6 M. f
- JB.setBounds(200, 60, 200, 30);
8 q- W- g8 W3 t$ W% E; |6 x - JB1.setBounds(200, 100, 200, 30);2 G1 {2 f: n3 n1 ]# }
- JB2.setBounds(200, 140,200, 30);; P+ o2 z: ~) T& P. k, O5 u
- JB3.setBounds(500, 400, 90, 30);; l4 k; A. D* Q
- ' ~) U! {& ]* y0 m. ?- }
6 N) l; Y! H/ H- container.add(JB);! x1 D! v4 h# @0 {( J
- container.add(JB1);7 o. u8 E0 ~* W* x9 @% T
- container.add(JB2);( g1 h6 u5 @6 {% P% c& u
- container.add(JB3);
) a2 W2 y' n) j1 B! \) ~( m) u - container.add(JL);
I" C8 n8 T8 z' r
$ L* x2 R: i `" V9 `# v- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);. r1 w$ L. a- P9 M( O
- setVisible(true);
' |( ]3 f+ @$ l/ m$ h8 \9 R. i - 8 T7 b/ }) B: {" Q
- }
' z3 c! f* w* U& y; Z# {
/ @+ k6 N4 a* t5 B7 T- private class MyMonitor implements ActionListener{
* {! _$ e5 B/ m6 f o$ a0 i* M - $ t8 b7 W; e H l& W j/ I
- public void actionPerformed(ActionEvent e) {
2 i1 ]' D4 G$ u) a! e - if(e.getSource()==JB){. I/ k- p, Q z& K) q
- new MyGraphy();% P( x |. t% c4 |3 k( }
- setVisible(false);7 v+ D& w/ m" X! E: a5 P
- }
* y& w) v8 e' K1 e# w% Y2 Q9 j - if(e.getSource()==JB1){* s K) P& {0 v/ n- U0 X
- new ShowLength();
5 i/ I/ j7 H6 V: t6 T - setVisible(false);
' M$ V7 R6 F. n9 p - }& B" C' N; {8 A5 a3 N+ l2 ?
- if(e.getSource()==JB2){$ p( B( I& b& z
- new ShowView();2 g- z1 b N0 A
- setVisible(false);1 w2 Y* t) [# H- n
- }3 ^* M# b- ^0 q$ N1 C
- 4 m" S: A- w( E% f/ b: N
- if(e.getSource()==JB3){
3 O2 G+ T2 T. \% y7 O' T Q+ A - System.exit(0);: T, t+ X$ L% w/ ^3 X( l
- }8 ?% M; m7 P) j% b$ }
- 2 f- G' f( M$ W2 Q2 `
- }
. ~5 R6 x* w9 z; Y
% j& A; \2 S3 ]3 S" _* L" \2 w- }
% n9 m1 R! y; S! ~) j! s% M - + }, v5 i v' ]& n' Q% k( I+ L
- public void paint(Graphics g){
% g0 L; K) U7 T% f - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
9 `7 K" L$ J; C: x" c$ ]0 Q: a
# e3 N ~' U# V/ Z; p8 o8 Y- }
4 r4 T3 S, O" H; D7 I" @
) ]1 }: c5 ~6 d! _! P0 Q$ k- + J+ }! \& i" u9 o" Q9 Y
- public static void main(String[] args) {
+ x6 }: t; l+ [! a4 [ - new Welcome();
( r: G j5 p8 r - }6 |( P" q; M7 K/ B+ b$ i( U
- }
0 l2 |5 N9 v& q& \2 ]
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
0 o7 S- V8 \( x4 n! B" q U |
|