Hallo
ich bin blutiger anfänger in sachen java.
ich habe ein problem, ich habe ein Programm das umgeschrieben werden muß damit ich mit Konfabulator darauf zugreifen kann.
Im moment sieht das Programm so aus daß auf dem Schreibtisch ein normales Programmfenster geöffnet wird.
(unwissend nehme ich an daß das mit swing gemacht wird oder?)
Naja jedenfalls ist das ganze nicht schön anzusehen und ich schreibe gerade ein Widget mit dem ich auf dieses Programm zugreifen möchte.
Die Beschreibung des Java Programms:
es ist wie eine Fernbedienung aufgebaut hiermit kann ich Fernseher DVD usw bedienen. zu dem Programm gehört eine HardwarePlatine die via Bluetooth angesprochen wird und die wiederum das Ir Signal an den Fernseher schickt.
nun im Konfabulator Widget würde ich das gerne so lößen
<img>
<onMouseDown>
HIER MÜSSTE DANN DER BEFEHL STEHEN DER AN DIE JAVA APPLICATION GEHT
</onMouseDown>
</image>
Ich werde auch die codes der App mal posten:
BlueRemote.java
BlueRemote.mf
BtParms.java
coke-cd.xml
dvd.xml
Makefile
Monitor.java
RemotePanel.java
XMLFile.java
XYLayout.java
Ich steig da nich durch und da ich nicht die Zeit habe Java zu lernen villeicht kann mir einer von euch helfen mein Problem zu lößen!?
ich bin blutiger anfänger in sachen java.
ich habe ein problem, ich habe ein Programm das umgeschrieben werden muß damit ich mit Konfabulator darauf zugreifen kann.
Im moment sieht das Programm so aus daß auf dem Schreibtisch ein normales Programmfenster geöffnet wird.
(unwissend nehme ich an daß das mit swing gemacht wird oder?)
Naja jedenfalls ist das ganze nicht schön anzusehen und ich schreibe gerade ein Widget mit dem ich auf dieses Programm zugreifen möchte.
Die Beschreibung des Java Programms:
es ist wie eine Fernbedienung aufgebaut hiermit kann ich Fernseher DVD usw bedienen. zu dem Programm gehört eine HardwarePlatine die via Bluetooth angesprochen wird und die wiederum das Ir Signal an den Fernseher schickt.
nun im Konfabulator Widget würde ich das gerne so lößen
<img>
<onMouseDown>
HIER MÜSSTE DANN DER BEFEHL STEHEN DER AN DIE JAVA APPLICATION GEHT
</onMouseDown>
</image>
Ich werde auch die codes der App mal posten:
BlueRemote.java
Code:
//
// BlueRemote - JSR82 compliant java BlueRemote client
//
// bluetooth interface
import javax.bluetooth.*;
// java Connection stuff
import javax.microedition.io.*;
import java.io.*;
import org.xml.sax.*;
// Gui related
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import de.beecon.*;
public class BlueRemote extends JFrame
implements ActionListener, DeviceFinder.BTControl {
static Config config;
static L2CAPConnection l2con;
static boolean connected = false;
static L2capThread l2capThread;
static DeviceFinder deviceFinder;
public boolean connecting = false;
Monitor monitor;
public void tx(String cmd) {
if(l2con != null) {
try {
l2con.send(cmd.getBytes());
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
// this is a thread handling the bluetooth communication with
// the blueremote
private class L2capThread extends Thread {
public L2capThread() {
super();
setDaemon(true);
}
public void run() {
try {
// System.out.println("mtu: " + l2con.getReceiveMTU());
byte b[] = new byte[l2con.getReceiveMTU()];
String str;
while(connected) {
if(l2con.ready()) {
// receive the packet
int len = l2con.receive(b);
monitor.processEvent(new String(b, 0, len));
} else {
// System.out.println("waiting");
try { wait(10); } catch(Exception e) {}
}
}
} catch(Exception ex) {
// ex.printStackTrace();
}
}
}
// the BlueRemote class creates the gui and starts the
// l2cap handler thread
public BlueRemote(String[] argv) {
super("BlueRemote");
monitor = new Monitor();
Container contentPane = getContentPane();
// build menu
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("File");
menu.setMnemonic(KeyEvent.VK_F);
JMenuItem menuItem = new JMenuItem("About");
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem("Quit");
menuItem.addActionListener(this);
menu.add(menuItem);
menubar.add(menu);
menu = new JMenu("BlueRemote");
menu.setMnemonic(KeyEvent.VK_B);
menuItem = new JMenuItem("Select ...");
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem("IR monitor ...");
menuItem.addActionListener(this);
menu.add(menuItem);
menubar.add(menu);
this.setJMenuBar(menubar);
RemotePanel remotePanel = new RemotePanel(this, argv);
contentPane.setLayout(new BorderLayout());
contentPane.add(remotePanel, BorderLayout.PAGE_START);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { quit(); }});
pack();
setLocationRelativeTo( null );
setVisible(true);
try {
// create a device finder waiting in the backround to
// be asked to search for devices
deviceFinder = new DeviceFinder(this, BtParms.name, BtParms.uuid);
} catch(Exception ex) {
ex.printStackTrace();
ErrorBox.show("Bluetooth Error", "Unable to start device finder."+
"\nERROR: " + ex.toString());
quit();
}
}
public void connect() {
System.out.println("connecting to " + config.getURL());
connecting = true;
Cursor oldCursor = this.getCursor();
this.setCursor(new Cursor(3));
try {
// create l2cap connection
l2con = (L2CAPConnection)
javax.microedition.io.Connector.open(config.getURL());
connected = true;
connecting = false;
this.setCursor(oldCursor);
// disable notification about port changes
tx("<set item=\"port report\" value=\"false\"/>");
System.out.println("BlueRemote connected");
// start l2cap handler thread
l2capThread = new L2capThread();
l2capThread.start();
} catch(Exception ex) {
ex.printStackTrace();
ErrorBox.show("BTkit IO error", "Error connecting Bluetooth device. "+
"You might want to select a new one!");
connecting = false;
this.setCursor(oldCursor);
}
}
public void disconnect() {
// request l2cap thread to stop
connected = false;
if(l2capThread == null) return;
// and wait for it to stop
while(l2capThread.isAlive()) { }
try { wait(1000); } catch(Exception e) {}
try {
l2con.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
void quit() {
disconnect();
Config.write("BTkit.BlueRemote", config);
System.exit(0);
}
// handle menu events
public void actionPerformed(ActionEvent e) {
if("About".equals(e.getActionCommand()))
About.beecon("BlueRemote", "1.0");
if("Quit".equals(e.getActionCommand()))
quit();
if("Select ...".equals(e.getActionCommand())) {
if(!connecting) {
try {
deviceFinder.requestDialog(config);
} catch(Exception ex) { }
} else {
ErrorBox.show("Bluetooth Busy",
"A connection setup is in progress. Plase " +
"wait a few seconds.");
}
}
if("IR monitor ...".equals(e.getActionCommand()))
monitor.show();
}
public static void main(String[] argv ) throws Exception {
System.out.println("BlueRemote L2CAP client V1.0");
if(false) {
if(argv.length < 1) {
System.out.println("Give at least 1 cmd file");
System.exit(0);
}
}
// create client
BlueRemote blueRemote = new BlueRemote(argv);
config = Config.read("BTkit.BlueRemote", blueRemote.deviceFinder);
if(config == null) blueRemote.quit();
blueRemote.connect();
}
}
Code:
Manifest-Version: 1.0
Main-Class: BlueRemote
Code:
//
// BtParms.java
//
// Bluetooth parameters for BtKit
//
public class BtParms {
// name of xml l2cap service
final static String name = "BtKit/XML";
// uuid of the xml l2cap service
final static String uuid = "7b8062d88d4e41d596a4a6b13c7dea28";
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<device name="Coke-CD" grid="24,17">
<button label="1" place="1,1,5,1">
<irsend repeat="1" base="8263" code="43040f0700021aaaaaaaabbbbbbbbaaaabaaabbbbabbb8"/>
</button>
<button label="2" place="7,1,5,1">
<irsend repeat="1" base="8269" code="43040f0700021aaaaaaaabbbbbbbbbbaaaaaaaabbbbbb8"/>
</button>
<button label="3" place="13,1,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbbaaaaaaaabbbbbbb8"/>
</button>
<button label="4" place="19,1,5,1">
<irsend repeat="1" base="8268" code="43040f0700021aaaaaaaabbbbbbbbabbaaaaabaabbbbb8"/>
</button>
<button label="5" place="1,3,5,1">
<irsend repeat="1" base="8263" code="43040f0700021aaaaaaaabbbbbbbbbaabaaaaabbabbbb8"/>
</button>
<button label="6" place="7,3,5,1">
<irsend repeat="1" base="8269" code="43040f0700021aaaaaaaabbbbbbbbbabbbaaaabaaabbb8"/>
</button>
<button label="7" place="13,3,5,1">
<irsend repeat="1" base="8268" code="43040f0700021aaaaaaaabbbbbbbbbbbbbaaaaaaaabbb8"/>
</button>
<button label="8" place="19,3,5,1">
<irsend repeat="1" base="8262" code="43040f0700021aaaaaaaabbbbbbbbbabbaaaaabaabbbb8"/>
</button>
<button label="9" place="1,5,5,1">
<irsend repeat="1" base="8268" code="43040f0700021aaaaaaaabbbbbbbbbaabbaaaabbaabbb8"/>
</button>
<button label="0" place="7,5,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbbbabbaaaaabaabbb8"/>
</button>
<button label="Sound" place="13,5,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbbaaabaaaabbbabbb8"/>
</button>
<button label="Time" place="19,5,5,1">
<irsend repeat="1" base="8268" code="43040f0700021aaaaaaaabbbbbbbbbababaaaabababbb8"/>
</button>
<button label="Digest" place="1,7,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbbbbabaaaaaababbb8"/>
</button>
<button label="ESP" place="7,7,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbabaabaaababbabbb8"/>
</button>
<button label="Return" place="13,7,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbabbabaaabaababbb8"/>
</button>
<button label="PBC" place="19,7,5,1">
<irsend repeat="1" base="8262" code="43040f0700021aaaaaaaabbbbbbbbaabbaababbaabbab8"/>
</button>
<button label="OSD" place="1,9,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbaaaaaababbbbbbab8"/>
</button>
<button label="A-B" place="7,9,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbaaabaababbbabbab8"/>
</button>
<button label="Slow" place="13,9,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbaabaaaaabbabbbbb8"/>
</button>
<button label="Mode" place="19,9,5,1">
<irsend repeat="1" base="8262" code="43040f0700021aaaaaaaabbbbbbbbaaaaaaaabbbbbbbb8"/>
</button>
<button label="Vol-" place="1,11,5,1">
<irsend repeat="1" base="8266" code="4304100700021aaaaaaaabbbbbbbbabaaaaaababbbbbb8"/>
</button>
<button label="Vol+" place="7,11,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbbabaaaaaababbbbb8"/>
</button>
<button label="Zoom" place="13,11,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbaababababbababab8"/>
</button>
<button label="Mute" place="19,11,5,1">
<irsend repeat="1" base="8262" code="43040f0700021aaaaaaaabbbbbbbbbabbaabaabaabbab8"/>
</button>
<button label="&&" place="1,13,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbababaaaabababbbb8"/>
</button>
<button label="&&" place="7,13,5,1">
<irsend repeat="1" base="8266" code="43040f0700021aaaaaaaabbbbbbbbabbbbaaabaaaabbb8"/>
</button>
<button label="|&&" place="13,13,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbabbbaaaabaaabbbb8"/>
</button>
<button label="&&|" place="19,13,5,1">
<irsend repeat="1" base="8262" code="4304100700021aaaaaaaabbbbbbbbababbaaababaabbb8"/>
</button>
<button label="R/L" place="1,15,5,1">
<irsend repeat="1" base="8260" code="43040f0700021aaaaaaaabbbbbbbbaabbbaaabbaaabbb8"/>
</button>
<button label="&||" place="7,15,5,1">
<irsend repeat="1" base="8262" code="43040f0700021aaaaaaaabbbbbbbbaababaaabbababbb8"/>
</button>
<button label="[]" place="13,15,5,1">
<irsend repeat="1" base="8264" code="43040f0700021aaaaaaaabbbbbbbbbbbbaaaaaaaabbbb8"/>
</button>
<button label="P/N" place="19,15,5,1">
<irsend repeat="1" base="8268" code="43040f0700021aaaaaaaabbbbbbbbaabbaaaabbaabbbb8"/>
</button>
</device>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<device name="DVD" grid="10,10">
<button label="Power" place="1,1,4,1">
<irsend repeat="1" base="8314" code="43040f0700021aaaabaaababbabbbbbbbbaaaaaaaabbb8"/>
</button>
<button label="Test" place="1,3,4,1">
<irsend repeat="255" base="7372" code="13020001555540"/>
</button>
</device>
Code:
#
# Makefile for BlueRemote
#
PROJECT = BlueRemote
FILES = $(PROJECT) BtParms RemotePanel XMLFile XYLayout Monitor
ROOT = ..
AVETANA_BASE = $(ROOT)
AVETANA_BIN = $(AVETANA_BASE)/AvetanaBluetooth.jar
BEECON_BASE = $(ROOT)
CLEANFILES = *~ *.java CVS
CLASSES = $(FILES:=.class)
JAVASRC = $(FILES:=.java)
all: $(PROJECT).class $(PROJECT).jar
$(PROJECT).class: $(JAVASRC)
rm -f *.class
javac -classpath .:$(AVETANA_BIN):$(BEECON_BASE) $(PROJECT).java
# run with automatic device search
run: $(PROJECT).class $(PROJECT).jar
java -jar $(PROJECT).jar
# build complete jar file
$(PROJECT).jar: $(PROJECT).class
rm -rf avetana beecon
mkdir avetana; cd avetana; jar xf ../$(AVETANA_BIN)
mkdir beecon; cp -a $(BEECON_BASE)/de beecon
for n in $(CLEANFILES); do find beecon -name $$n -print0 | xargs -0r rm -rf; done
rm -rf avetana/META-INF
jar cmf $(PROJECT).mf $(PROJECT).jar *.class -C beecon . -C avetana .
rm -rf avetana beecon
Code:
//
// Monitor.java
//
// Gui related
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Monitor implements ActionListener {
private JFrame frame = null;
private JTextArea textArea;
void display(String s) {
textArea.append(s);
textArea.setCaretPosition(textArea.getDocument().getLength());
}
public Monitor() { }
void show() {
if(frame != null) return; // don't open a second view
frame = new JFrame("BtKit - IR monitor");
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BorderLayout());
textArea = new JTextArea(15, 60);
textArea.setMargin(new Insets(5,5,5,5));
textArea.setEditable(false);
textArea.setCursor(null); //inherit the panel's cursor
contentPane.add(new JScrollPane(textArea), BorderLayout.CENTER);
// ok button
JButton button = new JButton("Close");
button.addActionListener(this);
contentPane.add(button, BorderLayout.PAGE_END);
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
display("This monitor window displays incoming infrared "+
"events from the BtKits internal IR receiver.\n");
display("Point your IR remote control at the BtKits IR "+
"receiver and press a button. The resulting events\n");
display("can be used in XML configuration files for BlueRemote "+
"as well as the BtKit browser. Some\n");
display("Some remote controls will send only single events on "+
"a button press, others will repeat their signals\n");
display("over and over again or send alternating events."+
"Have a look at the example files on how to setup\n");
display("the XML configuration files accordingly.\n");
}
// called by bluetooth receiver thread to display events
public void processEvent(String event) {
if(frame != null) {
display("\n"+event);
}
}
public void actionPerformed(ActionEvent e) {
frame.dispose();
frame = null;
}
}
Code:
//
// RemotePanel.java
//
// The remote panel is a tabbed pane, onto which all the
// remotes are placed
//
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.image.*;
import de.beecon.*;
// the complete color tool
public class RemotePanel extends JPanel implements FileFilter {
String getExtension(File f) {
String ext = null, s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1)
ext = s.substring(i+1).toLowerCase();
return ext;
}
public boolean accept(File f) {
if (f.isDirectory()) { return false; }
String ext = getExtension(f);
if(ext != null)
if(ext.equals("xml")) return true;
return false;
}
void processFile(BlueRemote remote, JTabbedPane pane, String name) {
try {
XMLFile xmlFile = new XMLFile();
xmlFile.read(remote, pane, name);
} catch ( Exception ex ) {
System.out.println("exception");
ex.printStackTrace();
}
}
public RemotePanel(BlueRemote remote, String []cmdFiles) {
this.setLayout( new BorderLayout() );
JTabbedPane tabbedPane = new JTabbedPane();
this.add(tabbedPane);
// use files given on the command line
if(cmdFiles.length > 0) {
for(int i=0;i<cmdFiles.length;i++)
processFile(remote, tabbedPane, cmdFiles[i]);
} else {
// search for xml files ourselves
File[] files = new File(".").listFiles(this);
if(files.length == 0)
ErrorBox.show("No XML files found",
"Please make sure, that there are XML files\n"+
"in the current directory or give them as\n"+
"command line arguments.");
else
for(int i=0;i<files.length;i++)
processFile(remote, tabbedPane, files[i].getPath());
}
}
}
Code:
//
// XMLFile.java
//
// reads an xml file
//
import java.util.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/** An example application */
final public class XMLFile {
// default grid if nothing given in file
final static int XREZ = 8, YREZ = 16;
BlueRemote blueRemote;
JPanel panel;
LinkedList buttonList;
XMLButton xmlButton;
String paneName;
Hashtable colors = new Hashtable();
class XMLButton {
String id;
int currentCode;
LinkedList codeList;
}
class XMLSignal {
String base;
String code;
String repeat;
}
public XMLFile() {
buttonList = new LinkedList();
// Create Hashtable to map color name (String) to Color type
colors.put("green", Color.green);
colors.put("red", Color.red);
colors.put("blue", Color.blue);
colors.put("yellow", Color.yellow);
colors.put("magenta", Color.magenta);
colors.put("cyan", Color.cyan);
colors.put("orange", Color.orange);
colors.put("pink", Color.pink);
colors.put("white", Color.white);
colors.put("black", Color.black);
}
// this class is being fed with all thje
class XMLHandler
extends org.xml.sax.helpers.DefaultHandler
implements org.xml.sax.ContentHandler {
ActionListener buttonHandler = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// search for matching internal button
for(int i=0;i<buttonList.size();i++) {
XMLButton xmlButton = (XMLButton)buttonList.get(i);
if(xmlButton.id.equals(e.getActionCommand())) {
if(xmlButton.codeList.size() > 0) {
XMLSignal xmlSignal = (XMLSignal)xmlButton.codeList.get(
xmlButton.currentCode);
if(xmlSignal.repeat != null) {
blueRemote.tx("<irsend base=\""+xmlSignal.base+
"\" repeat=\""+xmlSignal.repeat+
"\" code=\""+xmlSignal.code+"\"/>");
} else {
blueRemote.tx("<irsend base=\""+xmlSignal.base+
"\" code=\""+xmlSignal.code+"\"/>");
}
// cycle through all the codes
xmlButton.currentCode++;
if(xmlButton.currentCode >= xmlButton.codeList.size())
xmlButton.currentCode = 0;
} else {
System.out.println("Error, no code!");
}
}
}
}
};
final public void startElement(String namespace, String localname,
String type, Attributes attributes )
throws SAXException {
if( type.equals("device") ) {
Dimension bsize = new Dimension();
String grid = attributes.getValue("grid");
paneName = attributes.getValue("name");
if(grid != null) {
StringTokenizer st = new StringTokenizer(grid,",");
bsize.width = Integer.parseInt(st.nextToken());
bsize.height = Integer.parseInt(st.nextToken());
} else {
bsize.width = XREZ;
bsize.height = YREZ;
}
panel.setLayout(new XYLayout(
new Dimension(bsize.width, bsize.height)));
}
if( type.equals("text") ) {
String label = attributes.getValue("label");
String place = attributes.getValue("place");
if((label != null)&&(place != null)) {
// create its visible representation
JLabel jLabel = new JLabel(label);
panel.add(place, jLabel);
}
}
if( type.equals("button") ) {
// use label to draw a button
String label = attributes.getValue("label");
String place = attributes.getValue("place");
if((label != null)&&(place != null)) {
// determine number of the new button
int buttonCount = buttonList.size();
// create a new internal button representation
xmlButton = new XMLButton();
xmlButton.id = Integer.toString(buttonCount);
xmlButton.currentCode = 0;
xmlButton.codeList = new LinkedList();
buttonList.add(xmlButton);
// and create its visible representation
JButton button = new JButton(label);
button.setActionCommand(Integer.toString(buttonCount));
button.addActionListener(buttonHandler);
String color = attributes.getValue("color");
if(color != null)
button.setBackground((Color)colors.get(color));
panel.add(place, button);
}
}
if( type.equals("irsend") ) {
if(xmlButton != null) {
String base = attributes.getValue("base");
String code = attributes.getValue("code");
String repeat = attributes.getValue("repeat");
if((base != null)&&(code != null)) {
XMLSignal xmlSignal = new XMLSignal();
xmlSignal.base = base;
xmlSignal.code = code;
xmlSignal.repeat = repeat;
xmlButton.codeList.add(xmlSignal);
}
}
}
}
final public void endElement(String namespace, String localname,
String type)
throws SAXException {
}
final public void characters(char[] ch, int start, int len ) {
}
}
final public XMLReader makeXMLReader() throws Exception {
final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
final SAXParser saxParser = saxParserFactory.newSAXParser();
final XMLReader parser = saxParser.getXMLReader();
return parser;
}
public void read(BlueRemote remote, JTabbedPane tabbedPane,
String name) throws Exception {
this.panel = new JPanel();
this.blueRemote = remote;
XMLReader reader = makeXMLReader();
reader.setContentHandler( new XMLHandler() );
reader.parse( new org.xml.sax.InputSource( name ));
tabbedPane.addTab(this.paneName, this.panel);
}
}
Code:
//
// XYLayout.java
//
// a layout manager placing components in a fixed grid
//
import java.awt.*;
import java.util.*;
import java.util.LinkedList;
class XYLayout implements LayoutManager {
final Dimension defaultDim = new Dimension(320,512);
Dimension gridSize;
private LinkedList componentList;
// information of position and size of an object
class XYComponent { Component c; int x, y, w, h; }
public XYLayout(Dimension gridSize) {
this.gridSize = gridSize;
componentList = new LinkedList();
}
public void addLayoutComponent(String n, Component c) {
try {
XYComponent xyComp = new XYComponent();
StringTokenizer st = new StringTokenizer(n,",");
xyComp.c = c;
xyComp.x = Integer.parseInt(st.nextToken());
xyComp.y = Integer.parseInt(st.nextToken());
xyComp.w = Integer.parseInt(st.nextToken());
xyComp.h = Integer.parseInt(st.nextToken());
componentList.add(xyComp);
} catch (Exception e) {}
}
public void removeLayoutComponent(Component c) {
// search object and remove it
for(int i=0;i<componentList.size();i++) {
XYComponent xyComp = (XYComponent)componentList.get(i);
if(xyComp.c == c) componentList.remove(i);
}
}
public Dimension preferredLayoutSize(Container parent) {
return defaultDim;
}
public Dimension minimumLayoutSize(Container parent) {
return defaultDim;
}
public void layoutContainer(Container parent) {
// System.out.println("layoutContainer(" +
// parent.getSize().width + "," +
// parent.getSize().height + ")");
int xScale = parent.getSize().width / gridSize.width;
int yScale = parent.getSize().height / gridSize.height;
for(int i=0;i<componentList.size();i++) {
XYComponent xyComp = (XYComponent)componentList.get(i);
xyComp.c.setBounds(xScale * xyComp.x, yScale * xyComp.y,
xScale * xyComp.w, yScale * xyComp.h);
xyComp.c.validate();
}
}
}
Ich steig da nich durch und da ich nicht die Zeit habe Java zu lernen villeicht kann mir einer von euch helfen mein Problem zu lößen!?