该用户从未签到
|
- import javax.swing.*;) K) Q" Y K3 \$ ^
- ) ~6 M; ^5 F2 z9 c
- import java.awt.*;4 t( e' F) W) I1 W0 M6 j( P
- import java.awt.event.*;
+ z, E4 G) O' E/ y6 h& Q - import java.awt.image.ImageObserver;
b- H M9 H# r
3 p' T- }& ]6 D- X- public class Welcome extends JFrame{: n" O% U4 r! P* `5 g5 ]
- /**! k, d0 \0 f* a0 h& _$ T8 E$ U6 c! q
- *
- A- q& n% m+ O l7 M7 G) H - */
! L( s& \( n1 I+ S1 I- ]7 Z) s+ N - private static final long serialVersionUID = 1L;
8 [ r4 S6 n1 g4 O/ w8 h+ X5 P - /**" Z# {2 _8 Q; p
- *
$ K4 t& j, Q4 J. D L" a$ Q - */
, }4 o$ n8 i M# i' H- N - private JButton JB,JB1,JB2,JB3;
- Y [- j* C1 F- \! R - private JLabel JL;$ e, P9 q9 P) n: k7 L# }% T
- private Image img;
5 O) o/ e2 `6 s Q3 [+ E! J' U" ^ - private Toolkit tool;
# O' W1 d# ]3 _
$ B3 p) w7 D$ E* g( K3 X- Welcome(){6 I: u/ C( L8 H8 G" F. l
- super("欢迎来到科帮网");9 ]8 o6 ~- Y! }% H C: N
- setSize(600,500);* E. A0 o9 x% X. y" i: ]
- setLocation(250, 150);- n- H# ~ O% o3 n" v
- Container container = getContentPane();
( f% V7 b) }9 B - tool = getToolkit();& S+ a! i1 o2 ]. c5 B7 j9 Z
- container.setLayout(null);6 Y1 o" {# O& D3 {
6 O8 t# D$ x4 a, l' b/ y9 e- JB = new JButton("查询学校景点信息");& X* Y; A, K: a) w# {
- JB1 = new JButton("查询2景点间的最短距离");2 d5 e9 O, J. V' d& v
- JB2 = new JButton("查询旅游路线");% R+ G0 F R7 L; m" N7 V
- JB3 = new JButton("退出");
, k! ^9 o* g! W4 v% Z - JL = new JLabel("欢迎使用校园导游咨询系统");8 B7 i: Y0 E# F$ r" z. {6 a' n* s5 ]
- img = tool.getImage("E://School.jpg");/ v# \3 C$ b& Q. G& r8 |
5 \. D8 Y' a- P0 e# e; E. R# w+ ]5 y- JB.addActionListener(new MyMonitor());
5 _2 B+ @5 P- @ - JB1.addActionListener(new MyMonitor());
! D9 p2 \; E$ B1 l! E6 ^' f - JB2.addActionListener(new MyMonitor());
" S1 G; t# {1 G; K! L" r! d - JB3.addActionListener((new MyMonitor()));( V1 ?8 V ~2 ^0 ~5 }
% M* D1 ]: a$ z6 G- JL.setBounds(180, 20, 300, 40);
- B3 z& ~- |6 @, s& h - JB.setBounds(200, 60, 200, 30);9 k: z- G' h' G9 i+ N8 F/ k( [
- JB1.setBounds(200, 100, 200, 30);
3 Q& u6 j/ _4 w/ X8 S - JB2.setBounds(200, 140,200, 30);6 G' L% w Z. S, ~: @
- JB3.setBounds(500, 400, 90, 30);
3 c% H1 Z; j. j6 _1 ? - U/ }: N* u2 F1 q
$ A" e9 m0 Q d4 C% a- container.add(JB);" y& F6 V7 q7 W' w
- container.add(JB1);& e5 R! u$ B4 r6 @9 d: F
- container.add(JB2);
$ h4 |! r z$ X1 ~/ ?/ v" | - container.add(JB3);& o1 A E9 `) }- q n; }: ~* X
- container.add(JL);1 `* H; [8 h* B9 U8 V
- : O. M, C( |. V& R+ v: S
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
% r6 X& ^6 L/ L) k# s9 o- |1 e - setVisible(true);
- l& T8 H. a9 Q$ F. q7 ~) E, Q - 3 ~4 h9 L r% q0 q# t
- }. F7 H0 x& r; ?6 Y6 b& C
' b: i: _ K; e' ]* U1 L8 e- private class MyMonitor implements ActionListener{
$ S% S0 R* X) J2 S2 Z7 d$ W
Y4 `. J8 l" O. a; F/ M7 [- public void actionPerformed(ActionEvent e) {
3 d( L% q% S$ F' F5 F( l0 t - if(e.getSource()==JB){
" g& J3 k7 j, p2 K4 s! R - new MyGraphy();! ?( [, w8 a u
- setVisible(false);
) a' r% z- J1 ` - }
5 R- G. c% h* z9 a( L; U* K - if(e.getSource()==JB1){
' Q- P5 Q5 w" s6 i - new ShowLength();: {' n2 u7 ~3 j8 I3 n( @; W
- setVisible(false);! F( k( g# f. ^
- }
|1 }& Q0 N. J; _# }, ^ C - if(e.getSource()==JB2){
z/ [' n6 N6 v - new ShowView();
5 b$ {9 d& J, Y3 T - setVisible(false);1 i# w9 r. [" q8 M
- }2 N* b/ Q, E; g7 }9 f
5 p. A; \' ~' C. R0 Z- if(e.getSource()==JB3){
# v8 ]8 G5 d' O# H% b - System.exit(0);
* {; X6 s g- O! n - }
. A( e( j Q$ m$ M
& B2 v# ~0 P" F+ I9 V- }4 [) a; P8 d# S
' r: d8 _! u4 W" h6 E- }
t, ]% w) V, g" ?: S! e4 H - " c* }# L5 z" E. Q& R7 \ @6 C
- public void paint(Graphics g){" V* F+ X* J! A% \
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
' v" e+ p t% O0 z; x - " y9 {1 J& Y4 l7 r$ I* ]
- }
1 ?; }/ \) R$ x4 q, b9 c$ Z# s9 n - - }/ t7 T! {/ d4 w7 f: f# V; c7 \
- ! @" o+ J, u# ~! ~) Q
- public static void main(String[] args) {
" b% U9 h* `% m - new Welcome();
! f5 Z% Q. M0 m - }% s2 [2 g6 @9 P
- }
- @& m: c! n+ H
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)- a% F5 C) `* m( J5 {
|
|