该用户从未签到
|
- import javax.swing.*;0 D" ]' l# d' |! p( h
! u0 |1 U3 G9 U9 p2 m3 M- import java.awt.*;: ]( m3 G# f5 r
- import java.awt.event.*;( g) k( n6 L, O- r& j" ?1 d
- import java.awt.image.ImageObserver;
2 d3 W, O' ~4 R" j: N5 j+ K - + } G1 t( W3 A) W: D* Z! q, a
- public class Welcome extends JFrame{
0 H7 i( l5 y" s2 V/ p; h0 S - /**2 X9 X+ y3 B+ m" j" u% T$ C
- * 7 |) a2 E+ N. _( }
- */
- Q; j+ T+ s( b4 B5 u- | - private static final long serialVersionUID = 1L;- n+ l" S, o: I1 u! j4 J, {
- /**/ V4 N8 a+ R& a8 W6 R8 Q `
- * " I; A3 c% d8 t" `5 [0 a
- */( `' G0 {+ a2 F- H
- private JButton JB,JB1,JB2,JB3;* T0 d1 t8 Y% Y3 p
- private JLabel JL;% Z1 b# Y" U) T; l8 l2 w5 L
- private Image img;1 ^6 S9 j: y4 m0 W
- private Toolkit tool;
5 }. t* E" f0 f- ^0 L1 K
- c* w, k. Q2 B8 B. s6 {4 |- Welcome(){
0 g( J( V" @1 ?8 k - super("欢迎来到科帮网"); g1 z; F( t" R" c
- setSize(600,500);- M. @8 c9 W: L$ _9 X
- setLocation(250, 150);
1 _" s2 I* p% g6 \6 M- t - Container container = getContentPane();
( G/ N4 y6 p$ G1 ]& t - tool = getToolkit();
% q; Y; G* M+ P* d8 p. s - container.setLayout(null);6 V5 \$ m" m. B# f# f" S7 F
! u% u* S0 A( a- JB = new JButton("查询学校景点信息");
1 m X7 ]) M6 }2 c0 g; q c - JB1 = new JButton("查询2景点间的最短距离");
# B9 J2 v3 k6 c2 L9 `, o+ {3 N5 \7 R - JB2 = new JButton("查询旅游路线");9 p6 l4 V2 ~9 j& U* h
- JB3 = new JButton("退出");/ z4 _6 A- P; R' X# ~- Q
- JL = new JLabel("欢迎使用校园导游咨询系统");
% T9 C( N3 E- h! m. l - img = tool.getImage("E://School.jpg");. P0 u: D) s; j5 N/ K- O- B% T
- 7 O) }8 J) n: n/ _) l
- JB.addActionListener(new MyMonitor());
4 R* i. A( o- V& f0 }# n; y - JB1.addActionListener(new MyMonitor());- A& I6 Q& R7 E$ |# V7 \" _
- JB2.addActionListener(new MyMonitor());% |/ \9 l) f; X5 ]. d
- JB3.addActionListener((new MyMonitor()));- u, U b9 E8 z
- . g6 `7 z, T" X- l
- JL.setBounds(180, 20, 300, 40);
' F5 v4 U7 c3 ~! y0 p - JB.setBounds(200, 60, 200, 30);
" Q4 L7 N: k- O, D" s - JB1.setBounds(200, 100, 200, 30);
% E2 L& P- s" I8 e0 q" ^ - JB2.setBounds(200, 140,200, 30);' k) d! I* m) f; j3 K. a
- JB3.setBounds(500, 400, 90, 30);
* Y! d$ R. |7 r+ X$ N4 H' R. ~
4 @' G1 H) r$ a. M2 P
5 R8 @# ?7 D- r2 A( E3 P2 @1 [3 R- R- container.add(JB);
* A; A# e/ U1 ]6 v! z - container.add(JB1);1 K& J* k3 c( K- |9 [ ?, m* d
- container.add(JB2);
6 J' |4 [2 k! l& P6 b/ E8 _: U/ X - container.add(JB3);, n( w. d& I( V* D8 j
- container.add(JL);+ D" [' x5 R, N$ o
- ) a' M" H: C. B. v% a6 A
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
! Q3 ^% c/ ~; M4 J) S" [ - setVisible(true);
/ a6 R4 \' m e# v( W( q: z - 4 h4 x, p2 m$ U6 K Y: u* Y
- }
- h+ p2 U; M @" S: a# l/ _ - 4 G B! Y- K E
- private class MyMonitor implements ActionListener{
& e0 V: {0 l/ L2 z5 G. b8 S - + \1 t$ o% b% L% v# W# }2 ^) O
- public void actionPerformed(ActionEvent e) {
$ B, d+ e" r. j7 \8 a - if(e.getSource()==JB){
4 ]8 T& {2 I" s% }9 E- ]0 \ - new MyGraphy();
u0 G8 `* b4 Z; G- v* B - setVisible(false);; z" O: ?) G" V# O
- }) k1 z- r) k/ o, w6 |# W
- if(e.getSource()==JB1){
: O2 s" f: u6 k% Y - new ShowLength();# s5 `: H; A% J. N" [
- setVisible(false);
, J1 ^& M/ ^8 u$ [% S& p2 W8 n& V - }9 c- w( G9 s9 m" _9 y$ L. S* {
- if(e.getSource()==JB2){/ u7 o' g+ V7 T' ^8 M0 Q
- new ShowView();
: z* D5 A5 E K: \4 _ - setVisible(false);
# t2 ?' z1 _4 M8 _: K - }
P! s9 @& i$ ]* q5 B0 D0 K
7 d- O! Z3 q) p$ T0 @, |' W- P- if(e.getSource()==JB3){2 n; Y. {3 F1 V- r
- System.exit(0);
3 E4 L' b- A1 ^" Z! ]" X5 J - }
. H+ w' ]3 ^+ N+ a - ! v- j" ?, S. ]" m: q* H9 A; O
- }
5 k( r; `& ~ [& p+ r - ; E0 \9 ^) g( W8 h' n G. h
- }
' c1 U& r! V" f2 x( _ - : E2 m# F, \8 a, f7 Y
- public void paint(Graphics g){: d& |# j' |( `
- g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);( G$ l2 G; b6 u; j/ M
, c: ~+ v% t3 ]! T4 n% {- }
$ {" ]* s5 p2 Y5 j - 6 x2 @5 C" e4 W2 i$ t
- 8 A2 h8 |# K2 z# P) o: {
- public static void main(String[] args) {
6 ^- D$ S8 \/ L. t* ? J - new Welcome();
. p% y& x' Y$ x1 U1 C" ]! T6 d - }
/ A5 X- C4 ^4 u2 C. m3 Z$ ^7 M - }: V" h; U2 |3 g/ I
复制代码 原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)1 |" i5 i- @ O" q2 @- N
|
|