diff options
Diffstat (limited to 'com/trolltech/research/qtjambiawtbridge/examples')
-rw-r--r-- | com/trolltech/research/qtjambiawtbridge/examples/AwtInQt.java | 67 | ||||
-rw-r--r-- | com/trolltech/research/qtjambiawtbridge/examples/QtInAwt.java | 88 |
2 files changed, 155 insertions, 0 deletions
diff --git a/com/trolltech/research/qtjambiawtbridge/examples/AwtInQt.java b/com/trolltech/research/qtjambiawtbridge/examples/AwtInQt.java new file mode 100644 index 0000000..6a2f2eb --- /dev/null +++ b/com/trolltech/research/qtjambiawtbridge/examples/AwtInQt.java @@ -0,0 +1,67 @@ +package com.trolltech.research.qtjambiawtbridge.examples; + +import com.trolltech.qt.gui.*; +import com.trolltech.research.qtjambiawtbridge.QComponentHost; + +import javax.swing.*; +import java.awt.*; + +public class AwtInQt extends QWidget { + + public AwtInQt() { + QGridLayout layout = new QGridLayout(this); + + // A few Qt widgets + layout.addWidget(new QLabel("First name:"), 0, 0); + layout.addWidget(new QLineEdit(), 0, 1); + layout.addWidget(new QLabel("Last name:"), 1, 0); + layout.addWidget(new QLineEdit(), 1, 1); + + // The AWT part of the GUI + { + JPanel panel = new JPanel(); + + panel.setLayout(new GridLayout(1, 2)); + + panel.add(new JLabel("Social security number:")); + panel.add(new JTextField()); + + // Add the AWT panel to Qt's layout + layout.addWidget(new QComponentHost(panel), 2, 0, 1, 2); + } + + { + JPanel panel = new JPanel(); + + panel.setLayout(new GridLayout(2, 4)); + + panel.add(new JLabel("Phone number:")); + panel.add(new JTextField()); + + panel.add(new JLabel("Address:")); + panel.add(new JTextField()); + + panel.add(new JLabel("Credit card #:")); + panel.add(new JTextField()); + + panel.add(new JLabel("Expiration date:")); + panel.add(new JTextField()); + + // Add the AWT panel to Qt's layout + layout.addWidget(new QComponentHost(panel), 4, 0, 1, 2); + } + + } + + public static void main(String[] args) { + QApplication.initialize(args); + + AwtInQt awtInQt = new AwtInQt(); + awtInQt.show(); + + QApplication.exec(); + + System.exit(0); + } + +} diff --git a/com/trolltech/research/qtjambiawtbridge/examples/QtInAwt.java b/com/trolltech/research/qtjambiawtbridge/examples/QtInAwt.java new file mode 100644 index 0000000..bef356e --- /dev/null +++ b/com/trolltech/research/qtjambiawtbridge/examples/QtInAwt.java @@ -0,0 +1,88 @@ +package com.trolltech.research.qtjambiawtbridge.examples; + +import java.awt.GridLayout; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import com.trolltech.qt.gui.QApplication; +import com.trolltech.qt.gui.QGridLayout; +import com.trolltech.qt.gui.QLabel; +import com.trolltech.qt.gui.QLineEdit; +import com.trolltech.qt.gui.QWidget; +import com.trolltech.research.qtjambiawtbridge.QWidgetHost; + +public class QtInAwt extends JFrame { + + private static final long serialVersionUID = 1L; + + public QtInAwt() { + setLayout(new GridLayout(4, 1)); + + { + JPanel row = new JPanel(); + row.setLayout(new GridLayout(1, 2)); + row.add(new JLabel("First name:")); + row.add(new JTextField()); + + add(row); + } + + { + JPanel row = new JPanel(); + row.setLayout(new GridLayout(1, 2)); + row.add(new JLabel("Last name:")); + row.add(new JTextField()); + + add(row); + } + + // The Qt part of the GUI + { + QWidget row = new QWidget(); + QGridLayout layout = new QGridLayout(row); + layout.addWidget(new QLabel("Social security number:"), 0, 0); + layout.addWidget(new QLineEdit(), 0, 1); + + // Add the Qt widget to AWT's layout + add(new QWidgetHost(row)); + } + + { + QWidget row = new QWidget(); + QGridLayout layout = new QGridLayout(row); + layout.addWidget(new QLabel("Phone number:"), 0, 0); + layout.addWidget(new QLineEdit(), 0, 1); + + layout.addWidget(new QLabel("Address:"), 1, 0); + layout.addWidget(new QLineEdit(), 1, 1); + + layout.addWidget(new QLabel("Credit card #:"), 0, 2); + layout.addWidget(new QLineEdit(), 0, 3); + + layout.addWidget(new QLabel("Expiration date:"), 1, 2); + layout.addWidget(new QLineEdit(), 1, 3); + + // Add the Qt widget to AWT's layout + add(new QWidgetHost(row)); + } + + } + + public static void main(String args[]) { + // We have to initialize Qt Jambi in order to use its widgets + QApplication.initialize(args); + + QtInAwt qtInAwt = new QtInAwt(); + qtInAwt.setVisible(true); + qtInAwt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + qtInAwt.setSize(640, 480); + + // We need to run a Qt Jambi event loop in this thread in order + // for its widgets to receive events + QApplication.exec(); + } + +} |