该用户从未签到
|
- import javax.swing.*;
: Q3 F$ Y/ Z$ `
4 U3 C6 W3 P3 h1 Q- import java.awt.*;
% i6 `2 m: q; X1 |% M. O7 @9 a! w - import java.awt.event.*;
# T+ w4 r+ i) z- k# o2 D# w - import java.awt.image.ImageObserver;9 K" F% k- l, D9 R' ~2 L
& @+ C% z8 r }) K- public class Welcome extends JFrame{% c: S+ p$ p% b9 Q
- /**
1 R* p5 n* [( F9 @) V' o4 K W - *
% N7 v8 U" F" V. Y0 g - */
5 @% B$ j1 ^( g; b& z% j5 [3 [) h - private static final long serialVersionUID = 1L;6 i& k; S8 d# c0 x6 Z! @' H
- /**' E, [9 ^$ } r* l& Q: M% X
- * ! H; L& c% C1 n: q% G
- */4 H, i1 i4 y) E7 r o; c
- private JButton JB,JB1,JB2,JB3;# N; K* y2 A* Z
- private JLabel JL;3 e, a0 F% Z; O6 d9 `) Q/ A
- private Image img;- d% l% w( U9 d' J7 |6 s7 u5 v
- private Toolkit tool;# K: I/ Q( ^- R6 o- i3 N" [7 s
- , u3 b8 q0 H' E. i3 n9 N8 \, m4 l
- Welcome(){: y2 o" ]- }8 s
- super("欢迎来到科帮网"); N% j/ N* B2 r& L4 |3 y# C
- setSize(600,500);* A/ F3 _2 e* p, H8 W7 Q
- setLocation(250, 150);% n X, T J* v' T1 P/ d
- Container container = getContentPane();
) k `4 x+ S$ Y7 L" ?) i( a1 x - tool = getToolkit();5 }( g" H* }( L2 A j9 n
- container.setLayout(null);) u% `+ @& {' S# t: a8 U6 j
- ' T0 S. p. n+ u
- JB = new JButton("查询学校景点信息");
+ D4 D9 O' l5 o& t- [4 H4 d - JB1 = new JButton("查询2景点间的最短距离");
+ k5 b8 V2 n t% J( v - JB2 = new JButton("查询旅游路线"); D7 S& `" D4 C, Q
- JB3 = new JButton("退出");6 S" V2 A7 A5 t ~ z. d
- JL = new JLabel("欢迎使用校园导游咨询系统"); k2 n) ~ _8 p9 B: X p" p
- img = tool.getImage("E://School.jpg");
7 ~, b6 x& b9 A- K, o) w - 0 B. _. w1 b+ r7 V1 {0 r
- JB.addActionListener(new MyMonitor()); `2 e% h. T& o
- JB1.addActionListener(new MyMonitor());( q r" C1 l7 b4 _' M5 U& q$ r) Q: Z5 [
- JB2.addActionListener(new MyMonitor());. p# M/ K- @. t0 f# H7 G2 m; N% |
- JB3.addActionListener((new MyMonitor()));+ e" |2 [1 u, D4 o
- 3 x8 Z3 F; W& M9 r6 a1 R5 b
- JL.setBounds(180, 20, 300, 40);9 N0 n) @! m# F% J( S9 z4 U, s1 b
- JB.setBounds(200, 60, 200, 30);4 j/ K2 u. {. m; \0 D; ]
- JB1.setBounds(200, 100, 200, 30);
9 E- v2 V. N0 H- [ - JB2.setBounds(200, 140,200, 30);
4 L: k, L4 u; w. ]1 ] - JB3.setBounds(500, 400, 90, 30);
# r3 G' T: _+ U6 r - ! F2 ~% j- e! K$ |7 D7 X3 @
- A$ E, ~% `" U& N
- container.add(JB);5 |4 G3 b1 S9 Y; N. r' Y5 q
- container.add(JB1);: m8 d1 l5 W9 y
- container.add(JB2);9 C3 x l- l( f( m, B! q7 n6 J# f/ o
- container.add(JB3);
9 ~2 _; `. t) C- Q% M. \ - container.add(JL);
4 R3 C* O$ v% X9 p3 Z* U - 2 d' F9 g( i- k) N+ o, x' }/ h
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5 s+ a$ x( s9 S# i2 P! j9 _ - setVisible(true);
# O; r& B1 p9 p, o4 R9 H$ j
5 @& \# ]" A+ b- R4 q- }
0 h" O* |5 S# M; O
1 S# m; f/ q8 z2 m6 u; ?$ D8 ^- private class MyMonitor implements ActionListener{1 ]0 l9 D7 z8 u8 Z' D3 D
5 j6 {1 e8 }- s* w) j P1 j% Z; w- public void actionPerformed(ActionEvent e) {5 Y5 t9 L1 x; n* {
- if(e.getSource()==JB){# N. `; g& k7 V, i8 I
- new MyGraphy();
% x4 K0 Z# |0 i) ~" \& Z) x - setVisible(false);# a1 l$ s/ S2 v% q1 l) q
- }
8 a- L, _' p j5 X5 ?* }- D; n4 m- l - if(e.getSource()==JB1){
7 P8 E U8 V7 L+ r3 ?' V8 `- ] - new ShowLength();/ @' ^/ J2 w m3 h0 r
- setVisible(false);
6 ^; @9 Z. l0 V- k# I0 s - }
; `, N3 V7 u/ K. N. U - if(e.getSource()==JB2){7 b" }3 c v. t( U3 w
- new ShowView();
* R" K3 I2 f) g! `) x - setVisible(false);: @% ]- U( @, F* k; O" K" ~% x
- }
# E$ Z, q M# r2 Q- D( p% Z" u - ! P$ R b4 h* S" p6 O
- if(e.getSource()==JB3){/ q0 }# d$ N2 [6 d
- System.exit(0);
+ G6 E5 E* a# [ - }
; C6 c k3 p7 H: j' `" g - ! Y! C! s$ Z5 ]. [3 \
- }
, j$ j7 k4 P3 J5 D
) u$ E) M# l/ \1 K: Z- J- }1 r* O% y; D- H& M7 b/ j) B4 ]
9 S) ?" o4 V" N( T6 F- public void paint(Graphics g){
; _: v6 X, M5 L8 W- g* j - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
+ N; J! U# P2 }1 V - 8 h1 [9 h$ e# v" s
- }3 A) A- ~8 ] o) O0 l8 d
- 0 i) p9 ^/ ]* j2 U
- / L h1 W- V5 R- `8 P- \$ M4 i
- public static void main(String[] args) {2 C1 q0 g0 o" N" }$ u& H
- new Welcome();2 X' L5 N4 ^. g$ F
- }
, N8 P1 K0 C' r3 \0 y2 ]9 S4 M - }
% g3 O& C: ]# _' B R
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
9 H, i; O. @" I+ P |
|