该用户从未签到
|
- import javax.swing.*;% b# w+ R5 B3 j2 i: t; h
- 1 @$ R) b0 \6 W, S4 A/ Y: ?+ e
- import java.awt.*;# n( w) b" P9 m5 W) \6 J
- import java.awt.event.*;- M |* o+ v8 l- F( N
- import java.awt.image.ImageObserver;
2 r; j, c' U) }* m/ F - $ Z8 \3 ~( z5 f
- public class Welcome extends JFrame{
1 S& q0 I1 g) i! M! J - /**
. Q( E+ v3 Z% \8 `9 b# d' w - * # q; Y% E* ?" C4 a
- */" l' m2 D6 B3 `* Y7 t5 n& `
- private static final long serialVersionUID = 1L;
6 T, ~7 \: O H$ X) [( O6 W - /**3 O) Z" A% I2 ]6 w8 n& S
- *
6 d- G9 d( d/ V5 E& U1 g - */
# w& \9 J. V( x) b$ K) V) J3 P - private JButton JB,JB1,JB2,JB3;' G p* C' F: n: v
- private JLabel JL;
% Y4 Q4 F2 a5 e. O5 E& i - private Image img;. t J$ A/ W s% N5 ^
- private Toolkit tool;( }& @( X1 e5 A* z# o o
; k0 \+ T" ?4 F+ K: _1 `+ d- Welcome(){
0 ^2 z8 \% v- c) F6 a4 @, A - super("欢迎来到科帮网");
+ v7 N) A! A! Y `5 L - setSize(600,500);
7 K9 w- k3 f5 T# g @ X+ y - setLocation(250, 150);
5 n% W" c+ ]0 a6 {! Q - Container container = getContentPane();( u! ~! J, d$ U% K
- tool = getToolkit();7 y- y; q# R- f) m4 W _. L
- container.setLayout(null);# }. q) }/ |- C
" {+ r3 [1 O7 ^* j8 J6 [- JB = new JButton("查询学校景点信息"); A* Q2 H0 N: U \
- JB1 = new JButton("查询2景点间的最短距离");
* Y& D) m9 h/ U0 C" T/ p - JB2 = new JButton("查询旅游路线");
+ I" a9 @4 ?* Z" K% f) E - JB3 = new JButton("退出");
- b c) ?1 q+ g* }( W - JL = new JLabel("欢迎使用校园导游咨询系统");
. d' S) ^" L" M - img = tool.getImage("E://School.jpg");
/ S" y/ g, d) O: |5 N( E7 t5 {
, P5 c& r: K! k' f" A' _" V7 P- JB.addActionListener(new MyMonitor());
$ f2 {* K6 x u2 K, |3 Z - JB1.addActionListener(new MyMonitor());
3 [( T" _. n* n& |: ^. A0 V - JB2.addActionListener(new MyMonitor());/ e3 v, Q# r6 E! o x! E% i2 q
- JB3.addActionListener((new MyMonitor()));
+ U1 r- n' L5 m; {4 N5 _1 U
8 I- J: X1 g6 I5 i/ g1 K0 `3 [6 r- JL.setBounds(180, 20, 300, 40);
8 e4 K6 n* k! ^- ` - JB.setBounds(200, 60, 200, 30); F8 |! _- S$ w3 ^0 h
- JB1.setBounds(200, 100, 200, 30);5 `; b& o' F. x, m2 R& \3 r( q
- JB2.setBounds(200, 140,200, 30);
Q+ E8 [, A1 Q/ N6 [ - JB3.setBounds(500, 400, 90, 30);* r D, q3 z' f% p* L% b' h: \
- # b' L" N: v% b0 E! x6 F9 U1 M
# B2 r% Q3 A2 g! ~- container.add(JB);
# A8 i% {0 q- G, U1 J - container.add(JB1);
8 @8 v5 S. |7 M2 x# A$ X - container.add(JB2);
$ X, U" F$ j. S w6 M - container.add(JB3);
! {, ]3 G6 a+ g: n0 ? - container.add(JL);
9 J. W$ f0 q8 o4 N. Z; } - ' ~' f! L$ ]* D2 { `7 g
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
. C- G$ o" A+ C; t0 |& Z - setVisible(true);7 y% [& P) U9 i# N4 z9 [6 u
- : J! z, u ~( A5 z
- }5 X1 h* p3 x# C$ {- Z
- 4 s. t4 n$ z: W- L- ?0 } c% [0 t
- private class MyMonitor implements ActionListener{
" U6 G. l/ b( ~9 X4 a1 |$ s
1 ]6 N- ~# [$ J& B2 M, i7 s- public void actionPerformed(ActionEvent e) {
" A# v# h. p& |! E! G - if(e.getSource()==JB){
6 U% P/ `8 S/ p - new MyGraphy();
& W9 x3 V, E# b, H) M - setVisible(false);# Q* l) M* X1 P/ J! g \
- }/ O3 J8 U' R$ G5 p! q/ ?0 D
- if(e.getSource()==JB1){
6 f" l) m( M9 C - new ShowLength();
: r$ W* H, W$ i+ w# T+ I - setVisible(false); E1 \! a: D; r2 }9 ^
- }: b: O0 t' b2 G1 a3 I& f
- if(e.getSource()==JB2){
3 f5 A' d n- j7 i$ [+ m& U - new ShowView();- y3 G6 k2 k/ _/ [" P
- setVisible(false);5 A8 R$ P' ]+ e T! I6 I
- }
/ i- h4 m( H; P: W
' O# B' u Z0 h2 ~1 \- if(e.getSource()==JB3){8 |; Q4 T/ J2 {% l4 H
- System.exit(0);: r6 m* G' Y' @0 j. v( \ K# d
- }
' R H$ p; s; n4 d - ; p; H W4 n# M) f
- }# e# `8 ^" ?/ d0 P3 F( b: m$ [; w m3 W
- ' X4 P0 J: I1 m* G# j% I
- }
" b( D `6 v4 J* p* s0 v# Y - , o+ A) i& F# [+ O8 |6 o
- public void paint(Graphics g){! O6 N+ F9 o9 N" Q [+ }
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);# m' p$ M% t7 K
- . R5 |+ `' S( f2 Q' I4 h
- }5 t, O# N$ Z5 T
& i- Z. @6 R0 y! n- |- 9 V% Z! s8 W2 [7 l1 s9 A2 _* d: Z
- public static void main(String[] args) {
5 q3 j# l+ R+ `8 V. ?/ b7 z - new Welcome();5 B7 L. V1 T$ n2 [! i0 p- w
- }
% s& f z4 u/ X - }
1 O2 t- Z1 Q1 N
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
4 u/ n G3 }5 ^7 P2 r: _0 | z |
|