该用户从未签到
|
- import javax.swing.*;0 Q1 h' c* w0 b% _
- 6 K/ L2 g g' j8 B
- import java.awt.*;
3 P5 M6 O6 h- O& U* X) j) B' R8 ~# @- a) s8 ] - import java.awt.event.*;6 g3 }# m. c3 q$ ?/ Q
- import java.awt.image.ImageObserver;: @0 A6 C! B9 s2 Q
- / X. I& u7 u+ R3 h
- public class Welcome extends JFrame{4 i) O7 ]7 x( _. F& l+ I
- /**
7 I& S' ^6 y4 a - *
: p4 W2 u% U; s7 \ - */3 O. ]7 R0 Z) ^$ |
- private static final long serialVersionUID = 1L;
' [& a, E6 b. s - /**
* r& t/ m3 s9 u% b - *
) C1 W+ O& I! D8 D8 R! ~ - */" Y5 W/ f- R* Z2 h9 Q& L- }
- private JButton JB,JB1,JB2,JB3;
& g: p3 G2 g: A5 I6 } - private JLabel JL;
3 {/ ~. d4 f$ y# l9 c - private Image img;! i5 O m$ G. ^; t9 w
- private Toolkit tool;
2 F9 s! s+ J8 A) A - # H5 X' W2 o1 B- o9 u- V$ B& h
- Welcome(){
! n; z, ~( n( ] - super("欢迎来到科帮网");, y8 B- p8 a3 o, x! w1 j- |. c
- setSize(600,500);
0 g0 c" Q7 Q7 b - setLocation(250, 150);
4 S3 \$ k r8 a! Q) a, i - Container container = getContentPane();
/ {- g) ~0 a$ U; ^ - tool = getToolkit();
0 D9 v0 m' x% A2 f - container.setLayout(null);
! L) n+ Z( l6 |$ } - 5 l! I3 u. O4 g! V
- JB = new JButton("查询学校景点信息");5 c& A* ~/ d2 C5 |
- JB1 = new JButton("查询2景点间的最短距离");2 F. d4 T9 b/ Y: U; u+ Q8 W% y
- JB2 = new JButton("查询旅游路线");7 M/ I, h! J5 U! e/ d
- JB3 = new JButton("退出");
# @, x/ I0 o7 S1 a$ ~; ~) n - JL = new JLabel("欢迎使用校园导游咨询系统");
' O* D' m5 h2 L2 v n$ ~. w - img = tool.getImage("E://School.jpg");8 H7 i$ ]; X P, U `+ c, z' p
- ( ^1 r; ~5 ^9 A/ |4 v0 Q- M
- JB.addActionListener(new MyMonitor());0 P" p& p* r9 w* Z( E: V) {3 E9 o) {7 w
- JB1.addActionListener(new MyMonitor());
6 w: Y6 I$ {" d! Y1 ^& Q - JB2.addActionListener(new MyMonitor());
2 N9 \3 `6 n* r1 L5 E8 b4 w - JB3.addActionListener((new MyMonitor()));
9 {% G3 r+ H* l8 S6 D - 0 }3 _4 f5 `6 E8 g
- JL.setBounds(180, 20, 300, 40);& z" v4 P4 n# k' |
- JB.setBounds(200, 60, 200, 30);
7 o* k7 L: s( q) P# r( ` - JB1.setBounds(200, 100, 200, 30);3 d. C) L9 T$ m1 Z
- JB2.setBounds(200, 140,200, 30);
% z5 E9 l& E5 ?* H$ p A+ T' j - JB3.setBounds(500, 400, 90, 30);
C# s! h8 E6 P7 e! \# j - # p0 n/ T6 c) s$ N4 Z
6 y) ^4 X+ |( B% S1 E- container.add(JB);8 e" F* f+ B) E3 x5 @
- container.add(JB1);& S; P; ~3 d2 Q! w; L* S
- container.add(JB2);
1 s7 V$ W U! C9 _; J - container.add(JB3);
; E: [4 A' J7 a& W8 m7 S: S9 r - container.add(JL);" [2 g5 E/ a& }" t2 [ B. m
; o' @% c! J! y- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
% i7 I6 [% B0 X9 U& D, l - setVisible(true);
3 z% t; G; m5 n* l Z& }8 ? - u7 g: T: X+ L6 N) c7 F! D5 {
- }0 p' g& l" H, O: E% M1 x
2 i% ^6 Z% \# \: o8 @7 V- private class MyMonitor implements ActionListener{0 V! |; u9 F- j9 \9 W7 V
: d! _3 T8 ?! m* e# U3 L" ~7 J- public void actionPerformed(ActionEvent e) {
2 `! K d4 L4 _4 S& K - if(e.getSource()==JB){9 e( Y7 U/ F8 B, l2 _. n# e2 U
- new MyGraphy();4 z) j4 Z) S8 ^3 R. d& r
- setVisible(false);3 A' M: k& u; k. k, P+ ]7 I
- }+ N$ P0 z; S: z1 S, @ X% Q
- if(e.getSource()==JB1){
$ l1 y* `! |" W: W$ a: \" X4 S5 o - new ShowLength();
" `9 L a# d- q7 L/ h - setVisible(false);8 {2 @% y% B9 E
- }
3 v- |0 g7 F7 H7 U! }8 ]3 y+ {9 W - if(e.getSource()==JB2){2 b! ^# G& M* @. g
- new ShowView();
" l2 |6 |( B0 b+ ~: O( C! p( Q - setVisible(false);
0 H0 O5 q: ~# S+ F( S3 E - }
9 C7 J( b+ e: R7 O/ @0 L - 0 O, u* f& Q7 ~
- if(e.getSource()==JB3){0 H! k5 |8 f4 J) u
- System.exit(0);
" c9 _ F% {) v7 m - }9 K E l3 G; J8 y9 o, g- U& C
- 4 p+ ~# x4 z) q5 P! u! n
- }, m. S8 K' H# q" H( N
! B+ Y9 Z8 b+ b6 W% M6 W- F- }
- j) F K: d6 `; Q* @5 `! r - , Q3 w- J3 A P6 |6 s& j6 n O
- public void paint(Graphics g){
; I3 \ J% P" ` - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);1 S# a! |) R$ ^5 z( \
- $ w2 t! z3 m: [* e
- }
" F5 i# `4 H$ T - 8 U- K4 [" a& \8 L% ~: f0 c; |, n
8 _0 P& e, n1 S/ y( f. ~. [# c0 n- public static void main(String[] args) {
/ s7 W) c' s, U1 j G. V - new Welcome();
3 q; _9 B5 Q g, | - }; R, c; [- ^ x6 e
- }
) H6 r) e0 w M0 q+ S
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
# n' F) n8 w# Y2 { |
|