该用户从未签到
|
- import javax.swing.*;
& a9 @- z( o, j+ D0 t3 u
, l9 \2 Z3 g# A! r* I& v2 W- import java.awt.*; b- p8 P% ~. e N
- import java.awt.event.*;: X, R5 l$ _ H& |
- import java.awt.image.ImageObserver;1 j' \ ^" z7 }
! ]: x H: c% p8 @5 q0 @' n- public class Welcome extends JFrame{
6 h H; h& `! ?5 K+ K3 ]" A - /**
8 A- m" t- D D1 t - * 1 T: t( C+ @- y
- */$ A$ p0 ~- X k' v4 p. c
- private static final long serialVersionUID = 1L;7 F5 Y1 c# G" G( P- N1 ?. J. ^
- /**
2 X9 f, {( `! Z - * 9 I2 C a1 a' q. r+ N9 s" W
- */
& \1 V! i6 G9 V/ P1 Q - private JButton JB,JB1,JB2,JB3;# N9 I) S/ f: b r& w) {
- private JLabel JL;
! D' W% ^' H" p) @7 v4 U6 [' D: H- w - private Image img;6 u* s2 [& W2 U, t
- private Toolkit tool;
9 n5 j# h! G8 ~3 R& V - 0 r, O: P, ^9 _7 B
- Welcome(){
% i2 ^9 Q+ d2 I x3 H I$ T* f' X - super("欢迎来到科帮网");$ h0 T/ x8 J0 B" t+ l! v! j! ~
- setSize(600,500);. {: x/ S4 B& M. b) u* k
- setLocation(250, 150);7 X2 D! l: z9 e) U% Y+ B
- Container container = getContentPane();4 A, l* ^9 w# C" a( O1 Y
- tool = getToolkit();
/ K( v/ w5 z( X; O' Y' q( i - container.setLayout(null);. W, A4 S. `4 k( C$ j( s e3 ^9 W
- ; a0 ~& I8 c/ p, Q( e. r6 V
- JB = new JButton("查询学校景点信息");
& z+ d1 k( ~; s6 W# p- F - JB1 = new JButton("查询2景点间的最短距离");' \$ i; \1 W: l3 U3 [, g- }: e) ]
- JB2 = new JButton("查询旅游路线");- x* a$ w: P* ^2 b: m/ f
- JB3 = new JButton("退出");8 r) H5 `# W) n$ I5 N$ s
- JL = new JLabel("欢迎使用校园导游咨询系统");
! _# h' ~' U U( g - img = tool.getImage("E://School.jpg");3 c/ ?' O4 [3 g/ A& ~3 K/ @- L" a
( r: m; }& E L* t- JB.addActionListener(new MyMonitor());) O$ p- d& T O* n+ r7 o& a/ Q4 G
- JB1.addActionListener(new MyMonitor());
4 ~0 C$ [ H: I+ J - JB2.addActionListener(new MyMonitor());6 z9 J0 b9 Z0 {) Z. ?5 @* s
- JB3.addActionListener((new MyMonitor()));
3 q; q; b: g% c2 w, e
! @4 `) o6 L; p- J2 Z$ q1 v- JL.setBounds(180, 20, 300, 40);1 f7 i7 b! [% i
- JB.setBounds(200, 60, 200, 30);
1 `2 ]2 L: m6 w7 ^* l - JB1.setBounds(200, 100, 200, 30);
1 `! }/ ^' D# W. p% m/ h - JB2.setBounds(200, 140,200, 30);
2 W% Y) w4 T# E3 A - JB3.setBounds(500, 400, 90, 30);
8 B8 D8 D2 h2 q' L
0 t; u r+ A: n
$ n6 r( P0 `7 u4 O- container.add(JB);5 t7 G t# V# y0 C' C5 P8 N
- container.add(JB1);+ y+ v: u6 G, h( B
- container.add(JB2);
5 M6 e8 D& O' t) ^0 e - container.add(JB3);
* M T: }4 A: m3 j" L5 j - container.add(JL);
+ L. j+ i5 r- v" v0 ~
/ g9 P4 i0 G* x% g: M4 q; Q: t- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);( S9 f% O* l Q$ t G
- setVisible(true);
5 l; P1 B$ V! [, K- M+ x, F
@& F8 x6 V6 |9 j- }) e o7 h% l6 J6 F3 P8 B! S/ v
- 5 A# t) u8 |; u" X: K
- private class MyMonitor implements ActionListener{
6 |9 x0 r: Y2 h- N3 ]8 L - : h4 X2 |9 ]" T7 G; v
- public void actionPerformed(ActionEvent e) {
* y: p S" @4 Q8 N& G' p. v! ~0 v, s - if(e.getSource()==JB){5 @& I+ ?8 e ?: h
- new MyGraphy();! d* j( ?/ E" G; N- q* S3 B" l7 h
- setVisible(false);% S x" a; N% c& S
- }
. @! Y6 x8 V4 P* X1 G - if(e.getSource()==JB1){
; X+ J% F! w$ m5 V& u) K1 [ - new ShowLength();
5 z- C! G# L3 C+ k, E - setVisible(false);
( l) i3 V- d- ]; W9 S. b - }
) q1 h8 z0 z' n# g4 V5 q - if(e.getSource()==JB2){( F. H4 N ~1 V4 ^! x
- new ShowView();0 Z) p- M3 _' m z! f; T) ]
- setVisible(false); P9 J; I9 W. c I6 S& G2 h
- }
. r1 T# F; }" Y; b0 }* W/ G5 U - - t8 U3 l8 ~ S
- if(e.getSource()==JB3){
& {3 a7 Y, h; v2 f8 j1 [: g# W - System.exit(0);* Z3 L; F' ~7 Y; @( K( u# A
- }/ {2 N \" |- I; H0 n8 ?4 e1 \0 D
- 2 w6 |; a" F8 s
- }
9 k5 i0 G s# g8 K/ F: _
$ H2 V/ z; H. ^% q0 |0 O+ q, q- }
% _& ] d2 ?8 {- _, b/ V
# A5 I/ Y( S7 G; t- b' z- ^! }- public void paint(Graphics g){- j' L3 j& l- g/ M
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
5 n% _ q7 s9 P# d R a - ) b8 X4 A! p% B$ `# U( b' u
- }
Y7 |7 Z4 i Y2 W/ X( M
1 e2 J" ?# H+ [* L0 {( `1 |
/ O6 T; }+ V$ p6 T- public static void main(String[] args) {
: V+ v% w8 `1 ]5 F% Y# X& O - new Welcome();
% Q$ C M7 ?/ ?; _' I4 T - }, j% S4 b; v4 v7 x3 I7 q9 M, a8 P
- }0 W, K- o- v$ w( w0 ]* X) |) K
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
$ K7 C; l. S( L$ g3 P& }! n |
|