该用户从未签到
|
- import javax.swing.*; c4 Y) {3 S% s$ i# U2 r4 p' X' q
# t! C! z/ U$ Y: k- import java.awt.*;9 i. V/ S' b8 }$ _7 d( Z+ D* W
- import java.awt.event.*;$ E& R' V1 r; P# q% L
- import java.awt.image.ImageObserver;
[% u; o6 L0 _$ r. S; _, q
, Z0 {5 q. Z5 W& x* g+ P6 \# N- public class Welcome extends JFrame{% ^3 C% b+ V" P
- /**/ q9 ]3 x# x6 \- q {
- * $ O: C( ]! h+ g2 ], c+ W( m7 e8 b/ x
- */
% v. n# c3 F3 w/ E4 h9 A: [$ p D - private static final long serialVersionUID = 1L;/ e/ ~5 C% u& j- Z* o
- /**
* J" L; Q% ?4 \% N# T2 ~' V3 Q - *
4 q( n! F% B0 z% {0 W5 _' A3 } - */
* v2 e% a: l0 ~ - private JButton JB,JB1,JB2,JB3;
$ h5 H. r, h8 j$ g% F! @; c ] - private JLabel JL;
; T; {/ p% d8 Q; R - private Image img;
) j X: x. M3 F% r ]# B - private Toolkit tool;
! h* D7 R. B' }+ S3 ?+ s, B: v
3 v! o, q, t9 G3 m7 C' @( ~- Welcome(){
. u7 f8 o6 G5 r* g- N. {: R - super("欢迎来到科帮网");* q# D0 t" [- J8 @
- setSize(600,500);' e$ I. C. v* C, j; z1 h! u3 c$ k
- setLocation(250, 150);
( _" S9 A# H% Z. b; ? - Container container = getContentPane();& D9 z7 m" K+ q) i1 ]5 c. i: ~
- tool = getToolkit();
' i, m1 J; i6 L$ R ?. j - container.setLayout(null);
7 k; R- F8 U8 z2 k; I5 T - + S1 v; h( Y( ?8 b: V
- JB = new JButton("查询学校景点信息");% c2 o" S6 F) ^; C7 R0 d% S
- JB1 = new JButton("查询2景点间的最短距离");
1 M& c7 U9 N3 @. T - JB2 = new JButton("查询旅游路线");
3 M' k' g' {1 E8 }; L - JB3 = new JButton("退出");% p& ]. c8 H$ B1 e/ c
- JL = new JLabel("欢迎使用校园导游咨询系统");6 ]- u. D8 Q' Z. E% L
- img = tool.getImage("E://School.jpg");
0 P9 o5 h. p, e) C) o, H
6 F3 T) u2 X, c7 q4 b; V8 `7 C0 V8 S- JB.addActionListener(new MyMonitor());
2 N- V- `6 {1 {6 a) h/ e# O - JB1.addActionListener(new MyMonitor());
5 l* }6 }0 y1 o* h7 K/ z b# u - JB2.addActionListener(new MyMonitor());
" d7 C% k5 U8 H A+ J1 j - JB3.addActionListener((new MyMonitor()));
8 ~6 T; m" }+ A6 ~ - 7 k1 w) @" ~; V: o% ~" n* j/ ~. d
- JL.setBounds(180, 20, 300, 40);
& [! s3 ^7 o; R' }" f - JB.setBounds(200, 60, 200, 30);
, s) W( {8 g5 k0 W - JB1.setBounds(200, 100, 200, 30);
8 k P5 A. G) P3 |6 Q* [ - JB2.setBounds(200, 140,200, 30);, S: u) a( D# G6 h3 b) Y# F
- JB3.setBounds(500, 400, 90, 30);
! Y6 G/ T% ?8 E2 e" z6 q5 g - / h* h2 n( A/ F5 R
, d8 `4 G7 m8 a- container.add(JB);# i5 s" M. T7 r0 i
- container.add(JB1);" b' ^! p9 S2 ^
- container.add(JB2);. [7 @9 @* Q4 D& _9 A$ r
- container.add(JB3);6 \0 { H' C3 u5 Y
- container.add(JL); M# d7 c6 _4 w9 `( Y2 G
- ! f$ M* Q/ o( U
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
$ a$ ?7 E- ?+ T6 S7 Z4 m- W - setVisible(true);+ i8 b) Y, |: P& t9 Z- S j
- 7 c5 b3 y6 ~* c5 C) d [# O Z
- }( p3 \+ X' }. U. C6 C5 K
2 {- v1 N. N- W! I3 E# {$ X+ ]' g- private class MyMonitor implements ActionListener{% Z5 V) g _/ N- n" c& R+ D
- - X: _$ E, I2 c6 d$ h
- public void actionPerformed(ActionEvent e) {' z; q' h+ \4 [ [% I( v
- if(e.getSource()==JB){
7 |2 V8 B" y. @" J! n8 f/ V - new MyGraphy();
. V. s" }4 i' h- c, U( r* O - setVisible(false);
! `& ?7 a- }: _8 V3 ^4 Q) m4 D8 u. U( W7 F - }
+ ]! U% d' p) r1 Z - if(e.getSource()==JB1){
$ t d* Y8 X1 | - new ShowLength();
9 e; b+ P2 W" t, z8 n, g3 ` - setVisible(false);) O" V6 f' M0 O0 b" D; A
- }* X- S; U: b7 U0 O
- if(e.getSource()==JB2){
3 M% J8 r$ A# S( G. y' j - new ShowView();6 g8 \- E& V% _, p ]
- setVisible(false);
/ ~1 V. I) R; T" W - }) o, v0 ^' @1 k( X5 K, w
2 D/ s: F% M* E! E- if(e.getSource()==JB3){
2 L$ b3 U4 P1 u, X% t6 S - System.exit(0);+ x5 ?+ X6 w4 Y& {( F
- }& F3 }; I8 n. y; k) K. P6 M
% j; v, x2 j5 A- }* n( I% d3 N* j7 n8 T6 H
- + B0 ~4 C* S% q9 P. j/ a, j4 Q
- }
7 e2 o. v3 P& c
0 u0 O2 x# U) |' U/ Y) h- public void paint(Graphics g){, V# J1 {( q+ Z$ `
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);2 y1 `" i2 J; G. {( _1 L5 w+ \9 _
/ z% y, O9 A n* i5 n- }- K2 a3 U4 u% ]* Q3 U
: C1 c" f0 n: Q0 u# Z ?; U- + F' v# X1 F' \, I6 e0 e8 k
- public static void main(String[] args) {
/ w" a6 i: k, X- V: I7 }$ v - new Welcome();/ V/ z# X a8 \7 J
- }
& |0 V! I8 n; d0 L5 @ - } ?6 @5 Z0 M; Q) [7 n& ~3 n
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
4 t8 s. X8 g; F8 t y8 S/ a |
|