last 0,000 visited. -223695 today.
> owa > ZShogi > Shogi Applet > Shogi Applet
Ryuoh-sen 14-5
T.Hujii
Y.Habu
[109 / 109] 
Products
ZShogi
PyZume
Download
Let's try
MakeGame
MakePuzzle
Links
www.zope.org/Members/owa
www.coreblog.org
www.python.org
www.zope.org

This is a simple applet with javax.swing class.

applet is disable

Source
//
// SwingApplet.java:
//
//<applet height=280 width=206 code="SwingApplet.class"
//    archive="SwingApplet.jar" alt="applet is disable">
//    <param name="location" value="http://owa.as.wakwak.ne.jp/owa/arch/games/">
//    <param name="gameid" value="R14_5">
//    <param name="seqmax" value="109">
//    applet is disable
//</applet>

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
import javax.swing.table.*;
import java.io.*;

public class SwingApplet extends JApplet implements ActionListener {
    SwingViewPanel panel_view;
    JPanel panel_cntl;
    JButton btn_head;
    JButton btn_prev;
    JButton btn_next;
    JButton btn_tail;
    Color background = new Color(240, 240, 250);

    public void init(){
        String location = getParameter("location");
        String gameid = getParameter("gameid");

        JLabel title = new JLabel("ZShogi Applet Ver.0.1.4");
        JPanel panel_head = new JPanel();
        panel_head.add(title);
        panel_head.setFont(new Font("Serif", Font.BOLD, 20));
        panel_head.setBackground(new Color(200, 200, 140));
        panel_head.setForeground(Color.white);

        panel_view = new SwingViewPanel(location, gameid, this);
        //panel_view.setOpaque(false);
        panel_view.setBackground(background);
        panel_view.setFont(new Font("Mono", Font.PLAIN, 10));

        btn_head = create_button("ar_head.png", "head", KeyEvent.VK_HOME);
        btn_prev = create_button("ar_prev.png", "prev", KeyEvent.VK_LEFT);
        btn_next = create_button("ar_next.png", "next", KeyEvent.VK_RIGHT);
        btn_tail = create_button("ar_tail.png", "tail", KeyEvent.VK_END);

        panel_cntl = new JPanel();
        panel_cntl.add(btn_head);
        panel_cntl.add(btn_prev);
        panel_cntl.add(btn_next);
        panel_cntl.add(btn_tail);
        panel_cntl.setBackground(background);

        this.setLayout(new BorderLayout());
        this.add(panel_head, BorderLayout.NORTH);
        this.add(panel_view, BorderLayout.CENTER);
        this.add(panel_cntl, BorderLayout.SOUTH);

        init_panel(getRootPane());
        init_panel(panel_view);
        init_panel(panel_cntl);
    }
    private void create_menu() {
        //Create the menu bar.  Make it have a green background.
        JMenuBar greenMenuBar = new JMenuBar();
        greenMenuBar.setOpaque(true);
        greenMenuBar.setBackground(new Color(154, 165, 127));
        greenMenuBar.setPreferredSize(new Dimension(200, 20));
        setJMenuBar(greenMenuBar);
    }
    private JButton create_button(String icon, String name, int key) {
        URL ref = getDocumentBase();
        JButton btn = new JButton(new ImageIcon(getImage(ref, "img/" + icon)));
        Dimension size = new Dimension(35, 16);
        //btn.setMaximumSize(size);
        //btn.setMinimumSize(size);
        btn.setPreferredSize(size);
        btn.addActionListener(this);
        btn.setActionCommand(name);
        btn.setMnemonic(key);
        return btn;
    }
    private void init_panel(JComponent panel) {
        Action goFore = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                setButtons(panel_view.next());
            }
        };
        Action goBack = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                setButtons(panel_view.prev());
            }
        };
        panel.getInputMap().put(KeyStroke.getKeyStroke("LEFT"), "goBack");
        panel.getInputMap().put(KeyStroke.getKeyStroke("RIGHT"), "goFore");
        panel.getActionMap().put("goBack", goBack);
        panel.getActionMap().put("goFore", goFore);
        panel.setFocusable(true);
    }
    public void start() {
        panel_view.init();
    }
    public void stop() {
    }
    public void destroy() {
    }
    public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if (command.equals("head"))
            setButtons(panel_view.head());
        else if (command.equals("prev"))
            setButtons(panel_view.prev());
        else if (command.equals("next"))
            setButtons(panel_view.next());
        else if (command.equals("tail"))
            setButtons(panel_view.tail());
    }
    private void setButtons(int pos) {
        switch (pos) {
        case 0:
            btn_head.setEnabled(false);
            btn_prev.setEnabled(false);
            btn_next.setEnabled(true);
            btn_tail.setEnabled(true);
            break;
        case 1:
            btn_head.setEnabled(true);
            btn_prev.setEnabled(true);
            btn_next.setEnabled(true);
            btn_tail.setEnabled(true);
            break;
        case 2:
            btn_head.setEnabled(true);
            btn_prev.setEnabled(true);
            btn_next.setEnabled(false);
            btn_tail.setEnabled(false);
            break;
        }
    }
}

class SwingViewPanel extends JPanel {
    JApplet app;
    String location;
    String gameid;
    String title;
    String player1;
    String player2;
    int lastnumb;
    int sequence;
    Image image;
    Image img_south;
    Image img_north;
    Color background = new Color(240, 230, 210);
    MediaTracker mt = new MediaTracker(this);

    public SwingViewPanel(String url, String id, JApplet a) {
        location = url;
        gameid = id;
        app = a;
        try {
            lastnumb = Integer.parseInt(getInfo("/pubGetMaxNum"));
            sequence = Integer.parseInt(getInfo("/pubGetCurNum"));
            String u8 = getInfo("/pubGetTitle");
            title = new String(u8.getBytes("8859_1"), "UTF-8");
            u8 = getInfo("/pubGetPlayer1");
            player1 = new String(u8.getBytes("8859_1"), "UTF-8");
            u8 = getInfo("/pubGetPlayer2");
            player2 = new String(u8.getBytes("8859_1"), "UTF-8");
        }
        catch (java.lang.Exception e) {
        }
        finally {
        }
    }
    public void init() {
        setBackground(background);
        image = createImage(220, 220);
        img_north = createImage(206, 10);
        img_south = createImage(206, 10);
        setImage();
    }
    public String getInfo(String method){
        try {
            URL u = new URL(location + gameid + method);
            InputStream s = u.openStream();
            StringBuffer strbuf = new StringBuffer();
            int n = 0;
            int c = s.read();
            while (c != -1) {
                strbuf.insert(n++, (char)c);
                c = s.read();
            }
            s.close();
            return strbuf.toString();
        }
        catch (java.net.MalformedURLException e) {
        }
        catch (java.lang.Exception e) {
        }
        finally {
        }
        return null;
    }
    public void setImage(){
        String seq = "/show?seq=" + (new Integer(sequence).toString());
        try {
            // board image
            URL u = new URL(location + gameid + seq);
            image = app.getImage(u);
            mt.addImage(image, 0);
            //app.showStatus("Loading..." + u.toString());
            app.showStatus("Loading..." + gameid + seq);
            // north image
            Graphics gc = img_north.getGraphics();
            gc.setColor(background);
            gc.fillRect(0, 0, 220, 10);
            gc.setColor(Color.black);
            gc.setFont(new Font("Mono", Font.PLAIN, 10));
            gc.drawString(player2, 20, 8);
            // south image
            gc = img_south.getGraphics();
            gc.setColor(background);
            gc.fillRect(0, 0, 220, 10);
            gc.setColor(Color.black);
            gc.setFont(new Font("Mono", Font.PLAIN, 10));
            gc.drawString(sequence + "/" + lastnumb, 4, 8);
            gc.drawString(player1, 140, 8);
        }
        catch (java.net.MalformedURLException e) {
            image = createImage(10, 10);
        }
        catch (java.lang.Exception e) {
        }
        finally {
        }
    }
    public void paint(Graphics g) {
        if (mt.checkID(0,true)) {
            g.drawImage(img_north, 0, 22, this);
            g.drawImage(image, 0, 32, background, this);
            g.drawImage(img_south, 0, 210, this);
            g.setFont(new Font("Serif", Font.BOLD, 14));
            g.drawString(title, 40, 15);
            requestFocus();
            //app.showStatus("Loading image... complete");
        }
        else {
            repaint();
        }
    }
    public void update(Graphics g) {
        paint(g);
    }
    public int head() {
        if (sequence > 0) {
            sequence = 0;
            setImage();
            repaint();
        }
        return 0;
    }
    public int prev() {
        if (sequence > 0) {
            sequence--;
            setImage();
            repaint();
        }
        return (sequence > 0)? 1: 0;
    }
    public int next() {
        if (sequence < lastnumb) {
            sequence++;
            setImage();
            repaint();
        }
        return (sequence < lastnumb)? 1: 2;
    }
    public int tail() {
        if (sequence < lastnumb) {
            sequence = lastnumb;
            setImage();
            repaint();
        }
        return 2;
    }
}

Copyright © 2002-2024 Shu KONNO, all rights reserved since 2002/10/26.