该用户从未签到
|
- import javax.swing.*;3 Z# i0 L9 I( s, E# y4 n: X3 J0 d
- ( z" t5 G8 y* Q7 J4 y6 ]
- import java.awt.*;
- _: U( V" u9 N* ] }9 n& ~! K! L - import java.awt.event.*;
$ }5 T; j7 D* \' B' G' l- c - import java.awt.image.ImageObserver;
- m2 W2 |; |7 S4 @4 f7 J4 w& x
5 j: T* `* ]: O4 r1 w v5 Y# }- public class Welcome extends JFrame{
4 M3 Q9 ?9 q5 y: P8 H - /**) n e6 s F( Q
- * 2 M: e; N$ c- J& C0 i! {
- */
- L, Z) `2 W' X" N: }, v - private static final long serialVersionUID = 1L;
. U7 F) e4 Y0 k$ ~% h2 I+ H% E - /**
* x: A4 F& ^, X3 Y4 K2 ?* I - *
7 D# y" g( O' ~; ] - */
9 J2 L0 @) i& @# G' A: n - private JButton JB,JB1,JB2,JB3;
k8 g( p3 \+ E1 r7 ~ - private JLabel JL;
9 A% l) L& h* K* A7 m4 p+ o$ u - private Image img;
0 l2 |2 Q" g, E+ Z ^* {% Z - private Toolkit tool;
3 o5 C" O! ~, D - " ~) \% B9 M! k6 e! g
- Welcome(){
9 U$ e$ A" c; n/ B! g - super("欢迎来到科帮网");: w, t6 j( Z$ W3 C, D; @" m, f
- setSize(600,500);
' p1 N6 s8 X: b( [. K+ _ - setLocation(250, 150);
# u5 N0 n* m" \! M! r) J& i - Container container = getContentPane();
9 X' D' _0 |% ]6 d( S+ A3 w5 r - tool = getToolkit();1 i' h. l3 [7 D1 U
- container.setLayout(null);, N9 Q+ O; x" R7 t# f
- & V- Y: T2 ]0 F8 P/ d
- JB = new JButton("查询学校景点信息");- h, W6 e { t2 {
- JB1 = new JButton("查询2景点间的最短距离");$ \- ]) V. C0 s) e q# Q
- JB2 = new JButton("查询旅游路线");5 o/ w& C1 V- a0 u7 h* i
- JB3 = new JButton("退出");
" K. p4 W& n6 `0 G/ b - JL = new JLabel("欢迎使用校园导游咨询系统");
$ V6 ^' k1 [! O2 ?9 G- c - img = tool.getImage("E://School.jpg");2 n% ]$ m0 L) k Y
- * j* x" D1 D( ~& y- G
- JB.addActionListener(new MyMonitor());
! H& u! X: U2 d& G u - JB1.addActionListener(new MyMonitor());) \: k" \2 u: D1 d/ f1 A
- JB2.addActionListener(new MyMonitor());7 ^1 _) r% W V& p
- JB3.addActionListener((new MyMonitor()));5 }8 T8 c( V$ }! U5 b
. o9 w% i% v+ t0 z4 r1 T0 y- JL.setBounds(180, 20, 300, 40);
: |! t2 Q& K. w - JB.setBounds(200, 60, 200, 30);$ K* C* E7 [4 K& [- D
- JB1.setBounds(200, 100, 200, 30);
" \0 s( U0 `" @; n* p. W - JB2.setBounds(200, 140,200, 30);
1 ?6 P" z2 E5 O+ n/ J& ~( U% i, b0 { - JB3.setBounds(500, 400, 90, 30);' {. `4 k9 |: M( N0 A, e
- , u0 r: w8 z/ Z- O. c3 h& h, w
2 P# y+ [. Q; j' E! d) |- container.add(JB);
4 C) ?( I; z1 k- ^% L% P - container.add(JB1);3 M$ F; ^" F7 u- n# I2 `
- container.add(JB2);
: i; w4 F; y9 i2 S) U' i - container.add(JB3);
' Y' \! a0 e5 Z8 h8 v - container.add(JL);( y6 b4 g8 u4 y. @
2 y) F# o' N. \/ O- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- L+ @, F, @ {" w( q; D, `8 ~ - setVisible(true);
" |9 L/ Q6 ] o$ z - 0 `, p; g) ^/ J4 D7 ?% O
- }
3 y3 q" y- l; y4 s% g0 ?0 Y. t/ p" t - 3 L. m) M2 n: j
- private class MyMonitor implements ActionListener{
, M2 k7 ?7 N3 H" M; Z9 i& P
; U p, h6 X8 o" ^9 w, _8 y- public void actionPerformed(ActionEvent e) {
P# L* r5 u* E& f( l+ s) i - if(e.getSource()==JB){1 F& N! e& y1 i5 [0 `
- new MyGraphy();# w8 i+ o4 d3 F5 {& p
- setVisible(false);
$ q9 D* X4 T7 Z; h t* U - }9 R% F2 g; K7 H) G' b; i, h
- if(e.getSource()==JB1){
) f" L2 ^3 J0 @$ X$ ?6 K# T - new ShowLength();
B8 z& n7 ^: {8 @ - setVisible(false);
, r4 I8 i, E4 h ?7 \) C& D3 } - }
+ t* |) T- J" x6 ^/ a- P - if(e.getSource()==JB2){% l3 N! p4 e" Q7 L4 G
- new ShowView();
% s0 \1 q! ^' } - setVisible(false);
( O4 U' T M# V# j' J/ _$ l - }
" c+ |( M' W# h - * }/ n. i: [1 l; A# ^& a
- if(e.getSource()==JB3){6 W- M! d. y5 O
- System.exit(0);; x6 A' O1 n2 G
- }# f, M8 Q# }. s" s, V8 e5 O
- ( g {6 s9 g" @
- }
# x, A, m- p+ P7 X+ J, p* [; R
" W2 E) S9 |2 C4 X- }
& d' Q, p$ l: |# v8 \% _
( h7 J4 Q! C2 K H- public void paint(Graphics g){- x4 S0 B- ^1 R: P7 v
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);. O; }* @4 X/ S% G7 K
- # a( s$ E6 h' L' d8 V% X5 \3 L
- }$ k2 ~6 C) O, z6 E, c
4 }3 N. I, t$ _. y8 G- 8 H5 U3 L& Z0 n* N# _' t: f% g
- public static void main(String[] args) {( b2 ]. Q5 Q9 z: k! y9 Z0 R
- new Welcome();
% y y: |* F" i0 }2 L) q3 p. c - }0 Q7 b4 q' y3 t/ z9 X' s# n6 Q% r
- }6 I% M4 F" W- R0 {
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)( {0 z4 ~7 ~. k( Y
|
|