|
该用户从未签到
|
- import javax.swing.*;2 M. F, U- M _6 D: }
/ w4 W& e8 j6 N$ s9 N! d6 A8 @- import java.awt.*;
/ }, \) R/ \' M5 J. _4 i - import java.awt.event.*;$ O+ g/ f7 M- X5 W. D
- import java.awt.image.ImageObserver;9 \" |* y3 @9 m$ O) S
5 \, p, `9 B/ v5 c# z: c( k! j& r2 ~- public class Welcome extends JFrame{
# Z0 R) X. o# C9 |$ t - /**2 Z; y f: E5 u Z
- *
% f9 I+ V0 K9 n3 W' j' r( X - */1 h% ]& W! ?) X
- private static final long serialVersionUID = 1L;% I+ G0 c2 _0 c8 ]+ ^
- /**
5 G3 x$ w( ?/ R3 J - * ' v3 ?# T- P3 E; \8 a
- */" C) f4 M" I# x- [. y
- private JButton JB,JB1,JB2,JB3;
* I5 V9 q u7 O& G - private JLabel JL;5 L" e5 t! {& e2 _
- private Image img;9 K7 |0 q9 }& `$ D$ O) `
- private Toolkit tool;
; ?9 D A. r' l: U - & P$ t* Y3 Z' ~# u+ }+ ^% C0 s
- Welcome(){6 _6 q" ^/ J) N. c& L3 w) M
- super("欢迎来到科帮网");# |0 K H# i) c5 X- e, x2 s6 r
- setSize(600,500);
6 C9 o9 U) \% \ B2 j - setLocation(250, 150);: X5 p- T+ ?" l
- Container container = getContentPane();
5 B/ ^! i& E! ` \ - tool = getToolkit();, M/ \5 t0 [- a( M$ w7 ~
- container.setLayout(null);
% F2 W" _" C& D; L6 I4 K - 1 `- e" m; X: p9 m% i" S" a% E
- JB = new JButton("查询学校景点信息");
z* V4 Z3 C6 m! V - JB1 = new JButton("查询2景点间的最短距离");) _* t6 O- i, S& ~ e3 m
- JB2 = new JButton("查询旅游路线");1 ^9 b! r& W/ I7 p. R$ N
- JB3 = new JButton("退出");# l9 G0 {& [: r, B
- JL = new JLabel("欢迎使用校园导游咨询系统");1 ?* h( M" c" Z& ] z3 W
- img = tool.getImage("E://School.jpg");: ?" [! W* K5 w9 p2 |
- " h8 r. R3 a( y( L! K {1 ^
- JB.addActionListener(new MyMonitor());5 x) o. t7 }3 l4 |+ H9 a- `
- JB1.addActionListener(new MyMonitor());! U7 y8 m' z# g, J" _# [2 H
- JB2.addActionListener(new MyMonitor());
" M0 ~7 s1 z A# n3 U - JB3.addActionListener((new MyMonitor()));
U! b U7 [2 e# l1 l8 u - ' f% R+ t e" A- p0 c9 y
- JL.setBounds(180, 20, 300, 40);* f) S8 s v' U1 d$ U
- JB.setBounds(200, 60, 200, 30);
- s5 B8 ^" V. V2 t) m! ] - JB1.setBounds(200, 100, 200, 30);* E- y' S' ]4 J/ W; V
- JB2.setBounds(200, 140,200, 30);$ F* r" P5 Y, d, O
- JB3.setBounds(500, 400, 90, 30);
* i6 w# m# Y$ l
' ?9 h$ k9 b. K- {/ G) |5 E- 0 I% Y& q( |: e; L4 h
- container.add(JB);
+ V2 q4 \9 w/ A" i1 s [2 M- o - container.add(JB1);1 l) k/ E0 s2 M' \9 [- N7 ^
- container.add(JB2);
3 Y! v. `# R( b6 ] - container.add(JB3);
8 m5 O2 C6 R [1 v- u% ]) k) H5 { - container.add(JL);& h! ?" B, s( Y2 q
/ K) `3 J' m! s. l+ i- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);, f) O7 \) s5 ?- d: K! v
- setVisible(true);
& |2 K V* i" C - 6 m( a y x: X9 y* y2 N
- }$ A! }, S: P$ f1 k
) S4 R1 d. g- ?" X- private class MyMonitor implements ActionListener{2 G! m; D' l1 l) g0 `
. A1 Z& l) n- S6 n' U1 c( @: z! k" y. X- public void actionPerformed(ActionEvent e) {) R# x% `! z& D! o
- if(e.getSource()==JB){
@: B: w7 g( z; {+ _3 ^ - new MyGraphy();
! q7 g5 [: H9 i) } - setVisible(false);
* v; T+ I8 ?3 G7 i' ], g$ P - }
) v1 ?1 J: a8 K. D - if(e.getSource()==JB1){
1 V/ w+ E W, _8 R1 z4 g - new ShowLength();
: S4 j- s9 B3 y/ `3 k - setVisible(false);
- X2 R* J$ D9 ] - }) @& r w1 V( j$ ?
- if(e.getSource()==JB2){
" d' [; K" H$ }+ l- t - new ShowView();1 R- \1 A2 \* I7 B2 B9 p+ ^1 H
- setVisible(false);
1 R7 c$ L# Y# P. ] - }/ J' y7 v9 H/ n; u5 J
- 8 {* n# K. J! h& Q2 \4 O6 y
- if(e.getSource()==JB3){. l9 z- p( P. |' R: v
- System.exit(0);/ u5 L f& H, U s8 M
- }! J5 G& L, ?5 D* I
" O% \+ L8 M$ T' i9 @4 r4 h- }6 ^6 p' Y: A* F9 u+ r6 I2 }
5 b/ m- V( B6 c( j2 ? z/ Y- }/ p+ i) t- @9 k8 ^9 c8 s
3 e/ F* g9 d' i: o) o: M m0 k. P9 e- public void paint(Graphics g){
2 z$ l5 f4 s! o) }- M - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);1 W+ K! {, z4 S. B! o
8 }" x. \+ t9 D) n- }
" u9 t" d1 x ^) s* l$ D - & D5 \% ?* }6 l
- # g4 Q0 @1 s) x
- public static void main(String[] args) {
1 l0 G# F7 P, h8 r - new Welcome();' H+ j$ _1 N7 V. j6 C
- }2 \: U1 J3 ^$ t
- }, b3 y: n5 V4 k: b4 D8 @
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)3 T! b6 t9 o, J3 f( [9 E0 R& c2 o
|
|