该用户从未签到
|
- import javax.swing.*;3 G% s5 N; t% ~" o
- + z# @; ~5 T b& a; u
- import java.awt.*;
/ ], |- _( m3 Y7 l5 Q7 N - import java.awt.event.*;
3 v4 F2 ^) b3 V) ? - import java.awt.image.ImageObserver;, F- D( p3 o! [2 e
- * [" ]. N. _, r" ^3 c
- public class Welcome extends JFrame{: }$ w- P, e" ?9 X
- /**& ?# ~/ m8 d6 n; e$ E5 q
- * 1 a6 N/ m q5 D; X" F2 L
- */, ?# s% Z) N0 [1 l- ^- \2 v: l
- private static final long serialVersionUID = 1L;4 k6 d+ y2 B7 {0 k! x
- /**8 y2 a V( ?! V0 g, q
- *
& Q9 y) I# q/ E* t# h - */
5 Z: Z9 F3 j( { - private JButton JB,JB1,JB2,JB3;
3 K$ i) f6 ^/ V+ i - private JLabel JL;
' l7 u; I% j U9 P. h5 J0 I, h+ q - private Image img;" \1 U- C% ^9 G" M. Q
- private Toolkit tool;! J9 Q! J6 a. L
* E6 L% Q: Y3 k$ a7 s7 i3 x- Welcome(){6 S2 E' g& ^# h7 W) x( F. Y) d" i
- super("欢迎来到科帮网");. @6 }9 d4 m/ ^
- setSize(600,500);
y& y# e3 d( I1 Q, l/ p - setLocation(250, 150);: z% D# c' u# [, e# E8 Z4 i
- Container container = getContentPane();
: z/ Y0 o2 n% h, D9 W% c - tool = getToolkit();
4 ~# f5 U% ?: a$ B F - container.setLayout(null);
/ A- T; Q+ h& u4 m. c - - s$ L' { y' z: W
- JB = new JButton("查询学校景点信息");
- p" H3 w3 F2 ~6 _" P - JB1 = new JButton("查询2景点间的最短距离");! d. z# [- x( e, W' i5 Y* F0 G$ M* n/ X
- JB2 = new JButton("查询旅游路线");' h% V9 B- E+ y5 e
- JB3 = new JButton("退出");
% G: g! i3 ?/ A. `6 {, y* y - JL = new JLabel("欢迎使用校园导游咨询系统");
4 P; X) @6 N! |1 D5 c - img = tool.getImage("E://School.jpg");7 V# ?4 o8 p5 ?& T0 v" ^0 H; }8 g7 ]
) b; [( N$ Y, {# ?5 `1 P- JB.addActionListener(new MyMonitor());
: c L/ X& m* H0 |4 N2 Y" f - JB1.addActionListener(new MyMonitor());
4 D6 G" _* C0 | - JB2.addActionListener(new MyMonitor());
K$ N) `* q6 O - JB3.addActionListener((new MyMonitor()));
+ C$ m; K! W. B( z m$ [8 r8 Z& y
; N1 e; X! j8 P4 i9 r! h- JL.setBounds(180, 20, 300, 40);/ ?8 @9 p: D! |& p, [& u5 w
- JB.setBounds(200, 60, 200, 30);
, I& _2 S A. P4 l9 y( F - JB1.setBounds(200, 100, 200, 30);8 M8 h0 V/ }% Q; B
- JB2.setBounds(200, 140,200, 30);
% u0 r% w5 j, b/ S5 S/ L9 g B - JB3.setBounds(500, 400, 90, 30);
" ~6 P. g" Z" l5 d! D - - c/ z, j: v; o5 m% w, Q. H4 e
3 c. S( {5 Q/ B3 R0 e+ S6 _3 f- container.add(JB);
q; K O, M7 W A% x, B - container.add(JB1);/ {' @7 r% q4 S; f+ x
- container.add(JB2);
8 s! v: M& I* W+ ~8 n, \% r - container.add(JB3);% A+ t+ h3 n7 H1 _
- container.add(JL);
7 @2 s- x$ d f7 j# Q
" h6 n7 p: j; Q$ T4 k, V- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0 p. ~9 p4 B4 [/ j( I. o8 u0 B# q - setVisible(true);1 T+ X3 d$ K( ~
- 5 `8 w3 J& n! a
- }2 r( h7 B9 V: s- H! t8 q
- 1 n+ [8 V: e0 c8 z9 V) B' P# V) B5 O
- private class MyMonitor implements ActionListener{4 L; B5 z" s7 ?, R$ T {6 c0 s& x
- 7 ]1 m( d0 F/ ^" T; C
- public void actionPerformed(ActionEvent e) {$ M( q7 r6 M V2 Y# z) {
- if(e.getSource()==JB){! b1 i; H9 n; }& R! v/ R( U
- new MyGraphy();
9 N4 K: `; s4 p - setVisible(false);" Q2 n7 ?% g# d- w: g8 \
- }
/ c4 X. |4 u+ t( A' g. T - if(e.getSource()==JB1){! g* X; u$ ]1 I4 O" m* D
- new ShowLength();
9 t* B' k. |& a - setVisible(false);/ }8 H' y2 {1 ?& q/ C3 ^4 ^9 [
- }# g: E, e- \' E% u. `# K" N$ Y: q1 v
- if(e.getSource()==JB2){9 b! J7 T6 r3 A# A" W4 B) a
- new ShowView();" s1 }" o2 _( ~; M! D& [, v
- setVisible(false);$ R/ P# r" A8 R6 q4 P- ]
- }
: ^7 ~" r. d$ d, k8 F* S% i5 b
' H8 i6 w# } N E9 A' ?- if(e.getSource()==JB3){1 T2 B8 C2 E# c& {: Z! J
- System.exit(0);
8 b# ~7 T5 y+ P$ o - }
0 t' ^7 B% n# p- ~3 T N/ l
. }# j* w- m: l) O K& m9 m- }$ w& ]2 x+ b# K( y& @0 m1 X
- , R. p9 }. V" X0 ^( q' d r& B
- }$ n- q. k+ J2 C, i, o' h* g
: T) @; G' e A# O, u0 O D2 ]! a- public void paint(Graphics g){
9 [; G% S5 N* n' ]1 t) n. S. H% r - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
* w; x1 L( P& r& o- }
+ \& c: m; K9 `4 z1 Q0 R- }
( ?) S) K$ b9 f - $ i) |0 }& X8 |* p
G; a) g1 v+ ] t) t+ i, E- K- public static void main(String[] args) { h! q( L% T1 | I& |" |
- new Welcome();
8 b; K. q/ M. f& L( o H - }2 r3 M2 G3 C x
- }
2 C# r2 I s6 Y( f
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
0 B6 S( T, e9 m" s |
|