该用户从未签到
|
- import javax.swing.*;
8 [/ I5 G1 Q0 |9 w2 d& ^ - 5 X8 f& o' V j1 F; `; x4 I* _
- import java.awt.*;& d5 K/ G- B' r" h% g
- import java.awt.event.*;7 _4 b' r" \/ l, _* B
- import java.awt.image.ImageObserver;% D, Z# ?1 M% ]0 ~3 J
7 k8 g* }7 z2 i- public class Welcome extends JFrame{
# [6 }4 Z$ H* Y! s+ L3 w$ L9 D5 v - /**" F! m( M' t& f# q9 f
- * ( ]; `0 a: p$ g0 v% n- m
- */" c. R; D5 e# F1 ?* E. j7 Q
- private static final long serialVersionUID = 1L;
; B- }# O+ ~& C: T6 v5 s3 I! k: o - /** p. M2 a$ H" B1 V3 f
- * ; k* M3 p; X2 b* ^" r' c7 c$ i
- */
9 [3 K; r4 k! a. T) ]+ G - private JButton JB,JB1,JB2,JB3;
! N6 S! x1 a+ {3 [" k# `9 w - private JLabel JL;
& ^" O, G# m% f! \5 f4 G - private Image img;
2 a7 B [' g: m - private Toolkit tool;2 s; ` L1 T. f& s
- " k s( Z! P3 Z A: O1 O+ I+ L' D. S1 q
- Welcome(){: {3 F3 i, ? I
- super("欢迎来到科帮网");' B/ z2 b4 y) ^
- setSize(600,500);& J6 g7 Z; P( k! b% j6 B
- setLocation(250, 150);9 y/ s2 d5 W( r; }
- Container container = getContentPane();
' P! w, i* T$ E5 l7 Z8 Y6 ]$ r- p; o - tool = getToolkit();
; p7 ~0 D: s3 |& E - container.setLayout(null);! j7 v2 V* k# X; q6 A8 N
- ' e+ s$ K' j7 y; |' {3 e* W
- JB = new JButton("查询学校景点信息");* a$ E# `) Q8 B5 B; n3 C' v( L. ~! Z
- JB1 = new JButton("查询2景点间的最短距离");! D0 w7 @, \- [3 T2 K
- JB2 = new JButton("查询旅游路线");
, P% w+ S/ E; g2 Y4 q - JB3 = new JButton("退出");) B7 _2 [, [* h$ w. b7 A5 D6 Z
- JL = new JLabel("欢迎使用校园导游咨询系统");0 i0 E/ k" ?7 l, @. }/ o
- img = tool.getImage("E://School.jpg");6 k+ e6 q: }: Q
6 H: v# C8 [ Z- s. `, \! V& Z- N- JB.addActionListener(new MyMonitor());7 H8 Y8 r% e' G; V
- JB1.addActionListener(new MyMonitor());; }6 t& k% N& M0 m' m5 t Z$ C
- JB2.addActionListener(new MyMonitor());
9 f6 \: d8 m! I4 S" x' t - JB3.addActionListener((new MyMonitor()));, g. y! T' ^2 A9 g/ S+ u: G$ u
- 3 ]& f0 d+ v; W: l/ B. ^* k1 Y# W
- JL.setBounds(180, 20, 300, 40);
' b7 W2 F, Q. g5 g4 _' } - JB.setBounds(200, 60, 200, 30);3 W0 g( p$ \3 y7 `+ o+ l2 M* j' C, W
- JB1.setBounds(200, 100, 200, 30);# ?* u8 b7 }4 ]- H: o% M% g
- JB2.setBounds(200, 140,200, 30);
# J" ?3 c: b* O, @, e/ T - JB3.setBounds(500, 400, 90, 30);
% N# u$ o2 a% Q
" W8 O% _. f A. i- G. y- 8 J8 p7 _1 P& ?# n$ [
- container.add(JB);3 g% `5 l6 ?0 M
- container.add(JB1);
3 f) A$ a4 X; k% ~% q - container.add(JB2);$ h+ x/ J& F3 l% s/ ]1 u! X
- container.add(JB3);
e% s! z3 i, K4 r - container.add(JL);) {: P: c% d6 p3 a- y/ ?
- 3 S+ r1 }6 @. z2 U2 K
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);- |2 G( D' Z0 ^/ y* N5 W: e
- setVisible(true);
7 `$ U& m% q+ j( Q* ^7 Q" A
$ x' r! `: \3 o6 ]% E# X) ~- }6 a0 C7 D: V, }
- ' a7 O0 K) W/ E3 p* D0 F7 Q
- private class MyMonitor implements ActionListener{
. ^: ^' S$ m- B9 b* \" y
) ?. B& w) ^: o9 x+ h; x- public void actionPerformed(ActionEvent e) {
1 g a% u0 x! J# V1 z% P3 { - if(e.getSource()==JB){* R/ ^1 ]' M7 i- c& T
- new MyGraphy();
/ @# G( W( R( G/ K/ Y# ] - setVisible(false);4 P0 N% C g' H3 b2 I; a0 U
- }
" z- p Q! A" k5 z, b- Z - if(e.getSource()==JB1){
; S# Q+ }4 F+ Q0 S U. r - new ShowLength();, z4 p/ }# ^. s7 F* S0 k/ p; l! t4 {
- setVisible(false);
& e1 h! T4 U# s3 K& z3 [ - }. j5 t9 u* O. c( e
- if(e.getSource()==JB2){
1 b V- `6 g" I7 R9 e/ u; } - new ShowView();
5 Q$ e& _; L1 y% d' R4 c' z - setVisible(false);% j1 g3 w5 w0 |
- }4 j. l$ f+ M2 S& M, W
- & ^0 Z/ Q# M8 [ t% E; j7 R
- if(e.getSource()==JB3){
3 D7 w$ u5 d& @2 r - System.exit(0);
4 l2 u g. R6 ?; U - }. Y" a; w+ l$ m! Y( b
- $ _1 L7 e2 B# I! [
- }
6 v) p$ x$ y; I8 o; @& J
4 W& v4 K7 ^; y' Z- }, q. e: Q/ S. c: `0 m b
+ H6 K% G1 C4 s5 o/ m0 ?3 @- public void paint(Graphics g){
' {* V) F6 h, U0 ]0 R - g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
! |! r0 a: Z z5 ~* [8 |' V: y
2 \1 b- `% D/ K6 Y- }( \# E; ~, s& D5 U! m
9 r% u% {/ O8 p" _' Y& K- 6 ~5 }7 H$ R6 h
- public static void main(String[] args) {8 t% T4 m! |4 U# B& k
- new Welcome();
, X) B4 I1 A! i! p9 e9 S( o2 C - }
' r: f( f. e6 d7 q( ? - }, Y( _" R) z4 A) r& c" X6 {
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)1 _, P( |# c- m
|
|