static Window createInputMethodWindow(String title, InputContext context, boolean isSwing) { if (GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } if (isSwing) { return new InputMethodJFrame(title, context); } else { Toolkit toolkit = Toolkit.getDefaultToolkit(); if (toolkit instanceof InputMethodSupport) { return ((InputMethodSupport)toolkit).createInputMethodWindow( title, context); } } throw new InternalError("Input methods must be supported"); }
public static void main(final String[] args) throws HeadlessException { final Frame frame = new Frame("Test Frame"); final List list = new List(); frame.setSize(300, 200); list.add(ITEM_NAME); list.select(0); frame.add(list); frame.validate(); frame.setVisible(true); sleep(); if (!ITEM_NAME.equals(list.getSelectedItem())) { throw new RuntimeException("List item not selected item."); } list.removeAll(); frame.dispose(); }
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
public TestFrame(int width, int height, boolean undecorated) throws HeadlessException { super("Test Frame. Undecorated: " + undecorated); setSize(width, height); mrImage = new TestMultiResolutionImage(width, height); setUndecorated(undecorated); Panel panel = new Panel(new FlowLayout()) { @Override public void paint(Graphics g) { super.paint(g); AffineTransform tx = ((Graphics2D) g).getTransform(); mrImage.scaleX = tx.getScaleX(); mrImage.scaleY = tx.getScaleY(); Insets insets = getInsets(); g.drawImage(mrImage, insets.left, insets.bottom, null); } }; add(panel); }
private static AbstractAction getEncryptAction(final JTable table) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent me) { try { int col = table.getSelectedColumn(); int row = table.getSelectedRow(); if (col > -1 && row > -1) { String data = table.getValueAt(row, col).toString(); table.setValueAt(TMIntegration.encrypt(data), row, col); } } catch (HeadlessException ex) { Logger.getLogger(TMSettingsControl.class.getName()) .log(Level.SEVERE, ex.getMessage(), ex); } } }; }
private void btn_deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_deleteActionPerformed // untuk table delete. try { String sql = "DELETE FROM Product WHERE Prod_id ='" + txt_idProduct.getText() + "'"; java.sql.Connection conn = (java.sql.Connection) apsari.Koneksi.koneksiDB(); java.sql.PreparedStatement pst = conn.prepareStatement(sql); pst.execute(); JOptionPane.showMessageDialog(null, "Data akan dihapus?"); databaru = true; //kosongkan editor kiri txt_idProduct.setText(""); txt_namaProduct.setText(""); txt_hargaProduct.setText(""); } catch (SQLException | HeadlessException e) { } GetData(); }
public AppScannerInterface() { super(); initialize(); try { scanner = Scanner.getDevice(); //-- if (BoshScan.verifyAndInitComponets(scanner)) { boshScanListener = new BoshScanListener(); //-- scanner.addListener(boshScanListener); } else { JOptionPane.showMessageDialog(null, "No cumple con los requerimientos necesarios para \nusar twain4J", "Error", JOptionPane.ERROR_MESSAGE); } //-- } catch (HeadlessException e) { System.out.println(e.getMessage()); } }
private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed try { JFileChooser jfc = new JFileChooser(); jfc.setDialogTitle("Registerauszug speichern"); jfc.setFileFilter(new FileNameExtensionFilter("TEXT FILES", "txt", "text")); if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw); DataSetter ds = new DataSetter(); ds.writeToFile(bw, it); } } catch (HeadlessException | IOException e) { JOptionPane.showMessageDialog(this, "Error: IO"); } }
/** * @param savingImage the savingImage to set */ public void setSavingImage(boolean savingImage) { if (savingImage == true) { try { // Repeat the SavingImageTask without delay and with 5000ms between executions JFileChooser f = new JFileChooser(); f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int state = f.showSaveDialog(null); if (state == JFileChooser.APPROVE_OPTION) { savingImageTimer = new java.util.Timer(); savingImageTimer.scheduleAtFixedRate(new SaveImageTask(f.getSelectedFile()), 0, 5000); } } catch (HeadlessException e) {//Catch exception if any log.warning("Error: " + e.getMessage()); } } else { savingImageTimer.cancel(); savingImageTimer = null; } this.savingImage = savingImage; }
/** * Returns the <code>Desktop</code> instance of the current * browser context. On some platforms the Desktop API may not be * supported; use the {@link #isDesktopSupported} method to * determine if the current desktop is supported. * @return the Desktop instance of the current browser context * @throws HeadlessException if {@link * GraphicsEnvironment#isHeadless()} returns {@code true} * @throws UnsupportedOperationException if this class is not * supported on the current platform * @see #isDesktopSupported() * @see java.awt.GraphicsEnvironment#isHeadless */ public static synchronized Desktop getDesktop(){ if (GraphicsEnvironment.isHeadless()) throw new HeadlessException(); if (!Desktop.isDesktopSupported()) { throw new UnsupportedOperationException("Desktop API is not " + "supported on the current platform"); } sun.awt.AppContext context = sun.awt.AppContext.getAppContext(); Desktop desktop = (Desktop)context.get(Desktop.class); if (desktop == null) { desktop = new Desktop(); context.put(Desktop.class, desktop); } return desktop; }
@Override public int showOpenDialog(Component parent) throws HeadlessException { int ret = super.showOpenDialog(parent); if (ret == APPROVE_OPTION) update(); return ret; }
@Override public int showSaveDialog(Component parent) throws HeadlessException { int ret = super.showSaveDialog(parent); if (ret == APPROVE_OPTION) update(); return ret; }
private Rectangle getScreenBounds() throws HeadlessException { Rectangle virtualBounds = new Rectangle(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); if (gs.length == 0 || gs.length == 1) { return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); } for (GraphicsDevice gd : gs) { virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds()); } return virtualBounds; }
static private ColorModel colorModel(int transparency) { ColorModel model; try { model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration() .getColorModel(transparency); } catch(HeadlessException he) { model = ColorModel.getRGBdefault(); } return model; }
static private ColorModel colorModel(int transparency) { ColorModel model; try { model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration() .getColorModel(transparency); } catch(ArrayIndexOutOfBoundsException aioobE) { //#226279 model = ColorModel.getRGBdefault(); } catch(HeadlessException he) { model = ColorModel.getRGBdefault(); } return model; }
protected CheckboxPeer createCheckbox(Checkbox target) throws HeadlessException { throw new IllegalStateException("Method not implemented"); }
@Override public int showSaveDialog(Component component) throws HeadlessException { int result = super.showSaveDialog(component); if (result == JFileChooser.APPROVE_OPTION) { File sf = getSelectedFile(); String ext = SVGFileFilter.getExtension(sf); String fext = ((SVGFileFilter) getFileFilter()).getExtension(); if ((ext == null) || (!ext.equals(fext))) { File nsf = new File(sf.getAbsolutePath() + "." + fext); setSelectedFile(nsf); } } return result; }
@Override public int showDialog(Component parent, String approveButtonText) throws HeadlessException { int result = super.showDialog(parent, approveButtonText); if (result == APPROVE_OPTION) { saveCurrentDir(); } return result; }
public static void main(String args[]) { boolean exceptions = false; try { new JApplet(); } catch (HeadlessException e) { exceptions = true; } if (!exceptions) throw new RuntimeException("HeadlessException did not occur when expected"); }
static void cannotUndoRedo(RuntimeException ex) throws MissingResourceException, HeadlessException { if (ex.getMessage() != null) { JOptionPane.showMessageDialog( WindowManager.getDefault().getMainWindow(), ex.getMessage(), NbBundle.getMessage(UndoRedoAction.class, ex instanceof CannotUndoException ? "LBL_CannotUndo" : "LBL_CannotRedo"), JOptionPane.ERROR_MESSAGE); } }
@Override public int showSaveDialog(Component parent) throws HeadlessException { if (!FX_AVAILABLE) { return super.showSaveDialog(parent); } final CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override public void run() { // parent.setEnabled(false); if (isDirectorySelectionEnabled()) { currentFile = directoryChooser.showDialog(null); } else { currentFile = fileChooser.showSaveDialog(null); } latch.countDown(); // parent.setEnabled(true); } }); try { latch.await(); } catch (InterruptedException ex) { throw new RuntimeException(ex); } if (currentFile != null) { return JFileChooser.APPROVE_OPTION; } else { return JFileChooser.CANCEL_OPTION; } }
private static JFileChooser createFileChooser() { JFileChooser jf = new JFileChooser() { @Override protected JDialog createDialog(Component parent) throws HeadlessException { JDialog dialog = super.createDialog(parent); dialog.setIconImage(getFavIcon()); return dialog; } }; return jf; }
public HangmanUserInterface(HangmanLogic logiikka) throws HeadlessException { super(); setTitle("Hangman"); this.figure = new HangmanFigure(logiikka, this); add(this.figure); addKeyListener(new HirsipuuKeyAdapter(logiikka)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 400); }
public TestFrame(GraphicsConfiguration gc, Rectangle rect) throws HeadlessException { super(gc); setBounds(rect); mrImage = new TestMultiResolutionImage(rect.width, rect.height); JPanel panel = new JPanel(new FlowLayout()) { @Override public void paint(Graphics g) { super.paint(g); AffineTransform tx = ((Graphics2D) g).getTransform(); mrImage.scaleX = tx.getScaleX(); mrImage.scaleY = tx.getScaleY(); Insets insets = getInsets(); g.drawImage(mrImage, insets.left, insets.bottom, null); } }; JButton button = new JButton("Move to another display"); button.addActionListener((e) -> { GraphicsConfiguration config = getGraphicsConfiguration(); GraphicsDevice[] devices = GraphicsEnvironment .getLocalGraphicsEnvironment() .getScreenDevices(); int index = devices[screen1].getDefaultConfiguration().equals(config) ? screen2 : screen1; Rectangle r = getCenterRect(screenBounds[index]); frame.setBounds(r); }); panel.add(button); add(panel); }
public static Dimension getActualSize(Frame frame) { try { int extendedState = frame.getExtendedState(); java.awt.Rectangle bounds = frame.getMaximizedBounds(), systemBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); return new Dimension((extendedState&Frame.MAXIMIZED_HORIZ)==Frame.MAXIMIZED_HORIZ?(bounds!=null&&bounds.width !=Integer.MAX_VALUE?bounds.width :systemBounds.width ):frame.getWidth(), (extendedState&Frame.MAXIMIZED_VERT) ==Frame.MAXIMIZED_VERT ?(bounds!=null&&bounds.height!=Integer.MAX_VALUE?bounds.height:systemBounds.height):frame.getHeight()); } catch(HeadlessException e) { return frame.getSize(); } }
private void SaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveActionPerformed try { LoginHandling.save(getData()); JOptionPane.showMessageDialog(null,"Record Saved."); }catch (HeadlessException e) { JOptionPane.showMessageDialog(null, "Not Saved something went wrong."); } }
public void insertCustomer() { try { // for adding new data String sql = " UPDATE Customer SET First_name = ' " + text_namaAwal.getText() + " ' , Last_name = ' " + text_namaAkhir.getText() + " ' , Email_address = ' " + text_email.getText() + " ' WHERE Cust_id = "+strCust_id+" ;"; java.sql.Connection conn = (java.sql.Connection) apsari.Koneksi.koneksiDB(); java.sql.PreparedStatement pst = conn.prepareStatement(sql); pst.execute(); JOptionPane.showMessageDialog(null, "Data diri anda berhasil disimpan"); } catch (SQLException | HeadlessException e) { JOptionPane.showMessageDialog(null, e); } }
/** * Creates a new DropTarget given the <code>Component</code> * to associate itself with, an <code>int</code> representing * the default acceptable action(s) to * support, a <code>DropTargetListener</code> * to handle event processing, a <code>boolean</code> indicating * if the <code>DropTarget</code> is currently accepting drops, and * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>). * <P> * The Component will receive drops only if it is enabled. * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated * @param ops The default acceptable actions for this <code>DropTarget</code> * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code> * @param act Is the <code>DropTarget</code> accepting drops. * @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE> * @exception HeadlessException if GraphicsEnvironment.isHeadless() * returns true * @see java.awt.GraphicsEnvironment#isHeadless */ public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm) throws HeadlessException { if (GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } component = c; setDefaultActions(ops); if (dtl != null) try { addDropTargetListener(dtl); } catch (TooManyListenersException tmle) { // do nothing! } if (c != null) { c.setDropTarget(this); setActive(act); } if (fm != null) { flavorMap = fm; } else { flavorMap = SystemFlavorMap.getDefaultFlavorMap(); } }
private static boolean isReallyHeadless() { if (GraphicsEnvironment.isHeadless()) { //return true; } try { GraphicsDevice[] screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); return screenDevices == null || screenDevices.length == 0; } catch (HeadlessException e) { System.err.print(e); return true; } }
public DisplayWindow(int width, int height) throws HeadlessException{ super("Zombie Shooter"); this.width = width; this.height = height; setSize(600,600); drawArea = new DrawArea(600,600); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setContentPane(drawArea); setVisible(true); }
protected TextFieldPeer createTextField(TextField target) throws HeadlessException { throw new IllegalStateException("Method not implemented"); }
protected ListPeer createList(java.awt.List target) throws HeadlessException { throw new IllegalStateException("Method not implemented"); }
protected MenuBarPeer createMenuBar(MenuBar target) throws HeadlessException { throw new IllegalStateException("Method not implemented"); }
protected PopupMenuPeer createPopupMenu(PopupMenu target) throws HeadlessException { throw new IllegalStateException("Method not implemented"); }
protected MenuItemPeer createMenuItem(MenuItem target) throws HeadlessException { throw new IllegalStateException("Method not implemented"); }
public Map mapInputMethodHighlight(InputMethodHighlight highlight) throws HeadlessException { return Toolkit.getDefaultToolkit().mapInputMethodHighlight( highlight ); }