该用户从未签到
|
- import javax.swing.*;5 l4 }" u1 v& j" v
; \$ `2 K3 A$ n, T0 i- import java.awt.*;; t; U6 I* J0 m" Z4 {( Q
- import java.awt.event.*;
$ o' Y$ H7 u" F; p - import java.awt.image.ImageObserver;; I. i) A; A! ~0 l8 i: O6 p6 S
! F+ E# h! L& W4 z1 o- public class Welcome extends JFrame{' {4 a( \' ?( Q- ]+ [9 S
- /**
. T7 {+ w8 t/ \; r" V \( H - *
6 ~& P" m, ?9 \# e/ { - */1 a, h) h5 O3 K2 i
- private static final long serialVersionUID = 1L;
' T3 q. _6 y# n& b: V2 B - /**
: X, P; w, r2 ?/ d6 p8 z4 @ - *
0 X4 q& A3 p! W" Z2 J, {# n - */
: Q# W% ^) g" w - private JButton JB,JB1,JB2,JB3;- A; m; \ C5 @" _4 M: I$ X
- private JLabel JL;
) _2 R" {3 M5 h& L- ?# Y - private Image img;
3 o; A9 \+ }8 j4 f - private Toolkit tool;$ m! B0 s f; L+ L* o
- - E, _& m) R4 n M( f" Z
- Welcome(){
' \; i) _- y6 U - super("欢迎来到科帮网");
) k/ z# k: o* z$ b - setSize(600,500);
/ D* v+ o4 q3 _8 g) p - setLocation(250, 150);. y) C9 A+ R K/ ?; A1 s u" L( H
- Container container = getContentPane();
) u4 ?8 Y* v3 U. I" b- }/ ~ - tool = getToolkit();
4 t) e' D* y. h1 c - container.setLayout(null);" \" c: ~) U1 c+ K6 }0 T/ R0 ^
3 i0 ]1 k: \/ q( @. v- JB = new JButton("查询学校景点信息");, x. w) V, h' \
- JB1 = new JButton("查询2景点间的最短距离");5 i# l2 u1 M- w! `, g0 ]
- JB2 = new JButton("查询旅游路线");. ]: s) p8 K- r' x3 ~: n |2 D
- JB3 = new JButton("退出");
' ?2 c: M4 F1 t$ Y& X D - JL = new JLabel("欢迎使用校园导游咨询系统");
/ Z% g$ Y4 |( h$ [/ Z - img = tool.getImage("E://School.jpg");
9 e* k+ @ }: g# m3 ~! e - - u; H# d; t0 r
- JB.addActionListener(new MyMonitor());
1 ?5 }% f5 {; @* Z, Y | - JB1.addActionListener(new MyMonitor());
5 a4 |3 P% O6 A6 j! u, h$ v w% V& Q - JB2.addActionListener(new MyMonitor());
% F2 W7 W+ }% H! F: E+ r - JB3.addActionListener((new MyMonitor()));/ E$ ~5 ?5 {# x+ ?8 L4 b0 V' o. V
- 7 ]! ?, A+ n- I P& l- A, s- n
- JL.setBounds(180, 20, 300, 40);
7 X: T% O* r+ Q5 r5 c9 p - JB.setBounds(200, 60, 200, 30);/ S0 U# b: I7 l( K/ g8 r
- JB1.setBounds(200, 100, 200, 30);5 O& `8 l4 B. |: Z
- JB2.setBounds(200, 140,200, 30);
" }! G6 \3 p1 }6 y - JB3.setBounds(500, 400, 90, 30);" e$ b2 a, u! o- v. L
- : O ^0 w" u/ |8 w+ g
- * g1 ^' R9 r: U3 s3 |9 t0 P% N, G
- container.add(JB);7 O) ^+ G- P& y: Q9 |- V. w
- container.add(JB1);' ?7 t' o% N( I4 s$ p$ o( o
- container.add(JB2);6 W! p% \) W; J: a: `
- container.add(JB3);
/ f; E; M# w; r9 \ - container.add(JL);
' G6 ^! x+ _4 r3 |. B | - 1 A& ~4 _* A; v) `2 B8 z9 E$ y
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);) p/ J' A H" v8 w1 \4 M2 _8 E4 b
- setVisible(true);
' b# o1 m6 [2 O- T4 j( G h - 8 j. b; C( G7 ~! u3 B
- }
9 S8 Z9 i6 `# Q+ a. a4 M( i
4 h: P6 k/ `( _& o1 ]9 y2 F" q7 j- private class MyMonitor implements ActionListener{
- J: A, a7 i0 f: H3 v7 B
7 n- I& |5 e( G$ I u( J- public void actionPerformed(ActionEvent e) {# {% T, v1 i8 S
- if(e.getSource()==JB){
' j- A: e8 T& y& l' M5 |/ ?; r% [( U - new MyGraphy();
2 J. ~$ p; U+ D - setVisible(false);4 Z9 d; U- ^; ^1 s
- }( X/ v( Q. `& ^; L! g
- if(e.getSource()==JB1){! t7 t5 F7 r- K0 L$ H- C; @
- new ShowLength();
u( O! N4 h. v3 ^$ F; K( F - setVisible(false);( X0 |; [9 M* S9 e: b2 _3 l2 t# d
- }' K5 q0 b% q' W9 b l* g0 {3 G
- if(e.getSource()==JB2){: q2 Q T4 A+ O- \: w
- new ShowView();+ H. d- l) Y* Q
- setVisible(false);
+ z+ O5 {% ?& x+ M - }
. Z; v7 K) G6 e7 z5 q3 Z! @9 J
" B8 w! u5 e$ O5 A4 j- if(e.getSource()==JB3){# u' j. }- j8 I4 h: o1 ~: p
- System.exit(0);
! w" f# z/ o8 _) F - }
7 c/ u8 N" C2 G' X: ~! a
% O& H2 s9 S4 x9 T6 b1 R" u3 [- }
5 F# W% e# _1 S% y& _) u- ]: H - 8 _8 B, `0 Y; Y! O' B4 G
- }+ R8 u* f) \% q% H ^
- k$ T" ~; Y/ I6 M/ N- public void paint(Graphics g){
. x$ A0 d- m1 P1 v" M - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);1 Q h' g' k# i4 ~( K3 [; `1 d
- ' K |4 s$ o8 F' \
- }0 [0 Y- Z( m. |- W+ Q: @
* T: o* z' i% N& m" T- $ j' O5 V9 o- |3 S% ?& q5 E, X
- public static void main(String[] args) {9 |( O3 ~& y$ D0 i" Q
- new Welcome();; ?7 S, q7 b' Z6 F8 Z5 U
- }. S" G9 R1 ]! y
- }6 ^4 i0 y' B( Y& i
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
( Z! K9 G" _6 T4 Z( J |
|