public Fenetre() { setTitle("menu de l'application"); setSize(800, 600); /* creation barre de menu*/ barreMenus = new JMenuBar(); setJMenuBar(barreMenus); barreMenus.setBackground(Color.orange); // COULEUR DU MENU /* creation menu Fichier et ses options */ Fichier = new JMenu("Fichier"); barreMenus.add(Fichier); // ajoute le fichier a la barre de menu // sous menu fermer Fermer = new JMenuItem("Fermer"); Fichier.add(Fermer); // ajoute le sous menu fermer a l'onglet fichier Fermer.addActionListener(ec); Fermer.setForeground(Color.black); // COULEUR DU SOUS MENU Fermer.setBackground(Color.white); Connexion = new JMenu("Connexion"); barreMenus.add(Connexion); // sous menu lancer Lancer = new JMenuItem("Lancer la connexion"); Connexion.add(Lancer); Lancer.addActionListener(ec); // permet de mettre un écouteur sur le sous menu Lancer.setForeground(Color.black); // COULEUR DU SOUS MENU text couleur Lancer.setBackground(Color.white); // fond du sous menu mResa = new JMenu("réserver salle"); barreMenus.add(mResa); resa = new JMenuItem("nouvelle resérvation"); mResa.add(resa); // ajoute le sous menu "nouvelle resérvation" a l'onglet "réserver salle" resa.addActionListener(ec); resa.setForeground(Color.black); // COULEUR DU SOUS MENU text couleur resa.setBackground(Color.white); // fond du sous menu dateHeure = new JMenu("date et heure"); barreMenus.add(dateHeure); date = new JMenuItem("date et heure"); dateHeure.add(date); date.addActionListener(ec); // bouton surprise date.setForeground(Color.black); // COULEUR DU SOUS MENU text couleur date.setBackground(Color.white); // fond du sous menu this.setLocationRelativeTo(null); // fenetre afficher au centre de l'écran container.setLayout(new BorderLayout()); // JLabel label = new JLabel("Bienvenue sur le site"); JLabel label1 = new JLabel( "<html> MAISONS DES LIGUES<br><br> misson réservation<br><br>Cette application vous" + " permettra de vous connecter à notre base de données mrbs.</center><br> Vous pourrez rechercher des chambres " + "ainsi que le lieu de l'hotel.</html>"); container.add(label1, BorderLayout.CENTER); this.setContentPane(container); // ajout container à la fenetre setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
public CFrame() { super("Converter between Imperial and Metric."); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenu menu = new JMenu("Application"); menu.setBackground(white); menu.setMnemonic(KeyEvent.VK_A); // quit item JMenuItem item = new JMenuItem("Quit"); item.setBackground(white); item.setMnemonic(KeyEvent.VK_Q); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.gc(); System.exit(0); } }); menu.add(item); JMenuBar menuBar = new JMenuBar(); menuBar.setBackground(white); menuBar.add(menu); setJMenuBar(menuBar); setVisible(true); } // end of CFrame constructor
TBondPopupMenu(MolecularView v) { super("Torsional Bond"); view = v; miInfo = new JMenuItem("Info", new ImageIcon(getClass().getResource("resources/info.gif"))); miInfo.setBackground(new Color(0xFFFFD070)); miInfo.setEnabled(false); add(miInfo); addSeparator(); JMenuItem mi = new JMenuItem(view.getActionMap().get(Resource.get("Editor_java_jianqie"))); String s = MolecularContainer.getInternationalText(Resource.get("Editor_java_jianqie")); if (s != null) mi.setText(s); add(mi); addSeparator(); s = MolecularContainer.getInternationalText("Properties"); mi = new JMenuItem(s != null ? s : "Properties", IconPool.getIcon("properties")); mi.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { DialogFactory.showDialog(view.selectedComponent); } }); add(mi); pack(); }
protected void addMiProperties() { JMenuItem miProperties = new JMenuItem(app.getPlain("DrawingPad") + " ..."); miProperties.setIcon(app.getImageIcon("document-properties.png")); miProperties.setActionCommand("properties"); miProperties.addActionListener(this); miProperties.setBackground(bgColor); add(miProperties); }
public TypesMenu(AnnotationEditor editor) { super("Create new annotation"); this.editor = editor; // setEnabled(false); PropertyScheme scheme = Config.getPropertyScheme(); Vector annotFeatureProps = scheme.getAnnotationFeatureProps(); Iterator props = annotFeatureProps.iterator(); while (props.hasNext()) { String type = ((FeatureProperty) props.next()).getDisplayType(); JMenuItem typeItem = new JMenuItem(type); add(typeItem); typeItem.addActionListener(this); typeItem.setBackground(scheme.getFeatureProperty(type).getColour()); } }
private void addGeo(GeoElement geo) { // prevent selection of xOy plane if (geo == app.getKernel().getXOYPlane()) { return; } geoAddedForSelectAnother = true; GeoAction chooser = new GeoAction(geo); JMenuItem mi = selectAnotherMenu.add(chooser); mi.setBackground(bgColor); mi.setText(getDescription(geo, true)); mi.addMouseListener(new MyMouseAdapter(geo)); // prevent to add meta twice metas.add(geo); }
/* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JMenuItem getStopMenuItem() { if (ivjStopMenuItem == null) { try { ivjStopMenuItem = new javax.swing.JMenuItem(); ivjStopMenuItem.setName("StopMenuItem"); ivjStopMenuItem.setText("Stop"); ivjStopMenuItem.setBackground(java.awt.SystemColor.control); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjStopMenuItem; }
private void addAxesRatioItems(JMenu menu) { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { try { zoomYaxis(Double.parseDouble(e.getActionCommand())); } catch (Exception ex) { } } }; // get current axes ratio double scaleRatio = ((AbstractEuclidianView) app.getActiveEuclidianView()).getScaleRatio(); JMenuItem mi; // int perc; // ImageIcon icon; boolean separatorAdded = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < axesRatios.length; i++) { // build text like "1 : 2" sb.setLength(0); if (axesRatios[i] > 1.0) { sb.append((int) axesRatios[i]); sb.append(" : 1"); if (!separatorAdded) { menu.addSeparator(); separatorAdded = true; } } else { // factor if (axesRatios[i] == 1) menu.addSeparator(); sb.append("1 : "); sb.append((int) (1.0 / axesRatios[i])); } mi = new JCheckBoxMenuItem(sb.toString()); mi.setSelected(Kernel.isEqual(axesRatios[i], scaleRatio)); mi.setActionCommand("" + axesRatios[i]); mi.addActionListener(al); mi.setBackground(getBackground()); menu.add(mi); } }
public void refreshPopupItems() { if (!showPopUp) { return; } macrosPopup.removeAll(); TextArea ta = OJ.editor.getTextArea(); String macros_text = ta.getText(); int caretPos = ta.getCaretPosition(); String menuStrings = UtilsOJ.extractFunctions(macros_text, caretPos); String[] lines = menuStrings.split("\n"); Font theFont = new java.awt.Font("MS Sans Serif", 0, 12); // NOI18N for (int jj = 0; jj < lines.length; jj++) { String line = lines[jj]; if (line.length() > 5) { int lineNo = Integer.parseInt(line.substring(0, 5).trim()); char kind = line.charAt(6); char caret = line.charAt(7); String title = line.substring(8, line.length()); Color color = new Color(0, 0, 255); if (kind == 'f') { color = new Color(0, 100, 0); title = " " + title; } if (kind == 'b') { color = new Color(200, 0, 80); title = " " + title; } JMenuItem thisItem = new javax.swing.JMenuItem(title); thisItem.setAlignmentX((float) lineNo / 1000000); thisItem.setForeground(color); if (caret == '*') { thisItem.setBackground(new Color(255, 255, 188)); } thisItem.setFont(theFont); macrosPopup.add(thisItem); thisItem.addActionListener(itemAction); } } }
private void addZoomItems(JMenu menu) { int perc; ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { try { zoom(Double.parseDouble(e.getActionCommand())); } catch (Exception ex) { } } }; // ImageIcon icon; JMenuItem mi; boolean separatorAdded = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < zoomFactors.length; i++) { perc = (int) (zoomFactors[i] * 100.0); // build text like "125%" or "75%" sb.setLength(0); if (perc > 100) { } else { if (!separatorAdded) { menu.addSeparator(); separatorAdded = true; } } sb.append(perc); sb.append("%"); mi = new JMenuItem(sb.toString()); mi.setActionCommand("" + zoomFactors[i]); mi.addActionListener(al); mi.setBackground(getBackground()); menu.add(mi); } }
@Override protected void setTitle(String str) { AbstractAction titleAction = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { if (selectedGeos.size() < 2) { if (view.getMode() == EuclidianConstants.MODE_MOVE) { // change // selection // to // geo // clicked app.getSelectionManager().clearSelectedGeos(false); // repaint // done // next // step app.getSelectionManager().addSelectedGeo(getGeo()); } else { // use geo clicked to process mode Hits hits = new Hits(); hits.add(getGeo()); view.getEuclidianController().processMode(hits, false); } } } }; JMenuItem title = wrappedPopup.add(titleAction); title.setText(str); title.setFont(((AppD) app).getBoldFont()); title.setBackground(bgColor); title.setForeground(fgColor); title.setIcon(((AppD) app).getEmptyIcon()); title.setBorder(BorderFactory.createEmptyBorder(5, 0, 2, 15)); }
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.addWindowListener( new WindowAdapter() { @Override public void windowOpened(WindowEvent arg0) { // affichage de la boite de dialogue de chargement des données dialogLoadView dia = new dialogLoadView(frame, "Chargement des données", true); dia.setVisible(true); } }); frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout(0, 0)); panelEditView panelEditView_ = new panelEditView(); panelEditView_.getListResult().setBounds(37, 95, 364, 435); frame.getContentPane().add(panelEditView_, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); menuBar.setFont(new Font("Segoe UI", Font.PLAIN, 18)); menuBar.setBackground(Color.GRAY); frame.getContentPane().add(menuBar, BorderLayout.NORTH); JMenu menuFile = new JMenu("Fichier"); menuFile.setBackground(Color.GRAY); menuBar.add(menuFile); JMenuItem mntmNewMenuItem = new JMenuItem("Fermer"); mntmNewMenuItem.setBackground(Color.GRAY); menuFile.add(mntmNewMenuItem); // changement d'icon frame.setIconImage( new ImageIcon(MainApp.class.getResource("/images/logo-prevac-mini.png")).getImage()); // augmentation de la taille de la fenetre }
/** * Creates new ZoomMenu * * @param app * @param px * @param py */ public ContextMenuGraphicsWindow(Application app, double px, double py) { this(app); iconZoom = app.getImageIcon("zoom16.gif"); // zoom point this.px = px; this.py = py; EuclidianViewInterfaceCommon ev = app.getActiveEuclidianView(); if (ev.getEuclidianViewNo() == 2) { setTitle("<html>" + app.getPlain("DrawingPad2") + "</html>"); } else { setTitle("<html>" + app.getPlain("DrawingPad") + "</html>"); } addAxesAndGridCheckBoxes(); addSeparator(); // zoom for both axes JMenu zoomMenu = new JMenu(app.getMenu("Zoom")); zoomMenu.setIcon(iconZoom); zoomMenu.setBackground(getBackground()); addZoomItems(zoomMenu); add(zoomMenu); // zoom for y-axis JMenu yaxisMenu = new JMenu(app.getPlain("xAxis") + " : " + app.getPlain("yAxis")); yaxisMenu.setIcon(app.getEmptyIcon()); yaxisMenu.setBackground(getBackground()); addAxesRatioItems(yaxisMenu); add(yaxisMenu); JMenuItem miShowAllObjectsView = new JMenuItem(app.getPlain("ShowAllObjects")); miShowAllObjectsView.setIcon(app.getEmptyIcon()); miShowAllObjectsView.setActionCommand("showAllObjects"); miShowAllObjectsView.addActionListener(this); miShowAllObjectsView.setBackground(bgColor); add(miShowAllObjectsView); JMenuItem miStandardView = new JMenuItem(app.getPlain("StandardView")); setMenuShortCutAccelerator(miStandardView, 'M'); miStandardView.setIcon(app.getEmptyIcon()); miStandardView.setActionCommand("standardView"); miStandardView.addActionListener(this); miStandardView.setBackground(bgColor); add(miStandardView); addSeparator(); if (!ev.isZoomable()) { zoomMenu.setEnabled(false); yaxisMenu.setEnabled(false); miShowAllObjectsView.setEnabled(false); miStandardView.setEnabled(false); } if (ev.isUnitAxesRatio()) { yaxisMenu.setEnabled(false); } addMiProperties(); }
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // icon frame.setIconImage( new ImageIcon(this.getClass().getResource("/Textures/logoico.png")).getImage()); frame.addWindowFocusListener( new WindowFocusListener() { public void windowGainedFocus(WindowEvent arg0) { m_panelAnalyse.updateAnalyse(); } public void windowLostFocus(WindowEvent arg0) {} }); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { try { JOptionPane.showMessageDialog(null, "Fermeture"); SqlLiteInterface.close(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); frame.setSize(1152, 864); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu menuFichier = new JMenu("Fichier"); menuBar.add(menuFichier); mQuitter = new JMenuItem("Quitter"); mQuitter.addActionListener(this); mQuitter.setActionCommand("QUITTER"); menuFichier.add(mQuitter); JMenu menuEdition = new JMenu("Edition"); menuBar.add(menuEdition); JMenuItem mAddRir = new JMenuItem("Ajouter un RIR"); mAddRir.setActionCommand("ADDRIR"); mAddRir.addActionListener(this); menuEdition.add(mAddRir); mListRir = new JMenuItem("Lister l'ensemble des RIR"); mListRir.setActionCommand("LISTRIR"); mListRir.addActionListener(this); menuEdition.add(mListRir); menuRecherche = new JMenu("Recherche"); menuBar.add(menuRecherche); mRechercheDrogue = new JMenuItem("Recherche (Drogue)"); mRechercheDrogue.addActionListener(this); mRechercheDrogue.setActionCommand("RECHERCHE_DROGUE"); menuRecherche.add(mRechercheDrogue); mRechercheQuartier = new JMenuItem("Recherche (Quartier)"); mRechercheQuartier.addActionListener(this); mRechercheQuartier.setActionCommand("RECHERCHE_QUARTIER"); menuRecherche.add(mRechercheQuartier); mRecherchePersonne = new JMenuItem("Recherche d'une Personne"); mRecherchePersonne.addActionListener(this); mRecherchePersonne.setActionCommand("RECHERCHE_PERSONNE"); menuRecherche.add(mRecherchePersonne); mRechercheMtp = new JMenuItem("Recherche d'un Moyen de Transport"); mRechercheMtp.addActionListener(this); mRechercheMtp.setActionCommand("RECHERCHE_MTP"); menuRecherche.add(mRechercheMtp); mRechercheContact = new JMenuItem("Recherche d'un num\u00E9ro de Contact"); mRechercheContact.addActionListener(this); mRechercheContact.setActionCommand("RECHERCHE_CONTACT"); menuRecherche.add(mRechercheContact); mRechercheInfo = new JMenuItem("Recherche dans le contenu de l'information (RIR)"); mRechercheInfo.addActionListener(this); mRechercheInfo.setActionCommand("RECHERCHE_INFO"); menuRecherche.add(mRechercheInfo); mMultipleRecherche = new JMenuItem("Recherche crois\u00E9e"); mMultipleRecherche.addActionListener(this); mMultipleRecherche.setActionCommand("RECHERCHE_CROISEE"); mMultipleRecherche.setBackground(UIManager.getColor("activeCaption")); menuRecherche.add(mMultipleRecherche); menuAide = new JMenu("Aide"); menuBar.add(menuAide); mAbout = new JMenuItem("Au sujet de RirDrugsManager"); mAbout.setActionCommand("ABOUT"); mAbout.addActionListener(this); menuAide.add(mAbout); frame.getContentPane().setLayout(new BorderLayout(0, 64)); panelLogo = new panelLogo(); frame.getContentPane().add(panelLogo, BorderLayout.CENTER); m_panelAnalyse = new panelAnalyse(); frame.getContentPane().add(m_panelAnalyse, BorderLayout.SOUTH); panelDev = new JPanel(); FlowLayout flowLayout = (FlowLayout) panelDev.getLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); frame.getContentPane().add(panelDev, BorderLayout.NORTH); m_lDev = new JLabel("Developp\u00E9 par THONON C\u00E9dric"); m_lDev.setFont(new Font("Tahoma", Font.PLAIN, 9)); panelDev.add(m_lDev); // instance du sqlinterface sqlLite = new SqlLiteInterface(); try { // sqlLite.prepareSchemaSQLLITE(); sqlLite.prepareSchemaMYSQL(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, "Erreur de chargement de la class : " + e.getMessage()); } catch (SQLException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog( null, "Exception dans la requete de préparation du schema : " + e.getMessage()); } }
public MainWindow() { /*MenuBar*/ JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); /*Menu*/ JMenu menuFile = new JMenu("文件"); menuBar.add(menuFile); JMenu menuEdit = new JMenu("编辑"); menuBar.add(menuEdit); /*Menu item of File*/ JMenuItem menuItemNew = new JMenuItem("新建", new ImageIcon("image/menu_new.gif")); menuItemNew.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub newFile(); } }); JMenuItem menuItemOpen = new JMenuItem("打开", new ImageIcon("image/menu_open.gif")); menuItemOpen.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub try { openFile(); } catch (FileNotFoundException ex) { // TODO Auto-generated catch block JOptionPane.showConfirmDialog( pCanvas, ex.toString(), "无法保存文件", JOptionPane.CANCEL_OPTION); } } }); JMenuItem menuItemSave = new JMenuItem("保存", new ImageIcon("image/menu_save.gif")); menuItemSave.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub try { saveFile(); } catch (IOException ex) { // TODO Auto-generated catch block JOptionPane.showConfirmDialog( pCanvas, ex.toString(), "无法保存文件", JOptionPane.CANCEL_OPTION); } } }); JMenuItem menuItemSaveAs = new JMenuItem("另存为", new ImageIcon("image/menu_saveas.gif")); menuItemSaveAs.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub try { saveAsFile(); } catch (IOException ex) { // TODO Auto-generated catch block JOptionPane.showConfirmDialog( pCanvas, ex.toString(), "无法保存文件", JOptionPane.CANCEL_OPTION); } } }); menuFile.add(menuItemNew); menuFile.add(menuItemOpen); menuFile.add(menuItemSave); menuFile.add(menuItemSaveAs); /*Menu item of Edit*/ JMenuItem menuItemDraw = new JMenuItem("绘图", new ImageIcon("image/cursor_draw.gif")); menuItemDraw.setBackground(Color.WHITE); menuItemDraw.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub pCanvas.setMode(Mode.DRAW); } }); JMenuItem menuItemSelect = new JMenuItem("选择", new ImageIcon("image/cursor_selection.gif")); menuItemSelect.setBackground(Color.WHITE); menuItemSelect.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pCanvas.setMode(Mode.SELECT); } }); menuEdit.add(menuItemDraw); menuEdit.add(menuItemSelect); /*Panels*/ JPanel pMain = new JPanel(new BorderLayout()); /*The main panel*/ JToolBar pOption = new JToolBar(); /*The option panel*/ pCanvas.setBackground(Color.WHITE); pCanvas.setShape(Button.LINE); pCanvas.setMode(Mode.DRAW); pCanvas.setColor(new Color(0, 0, 0)); add(pMain); /*Components of option panel*/ /*Button of drawing Line*/ btnDrawLine = new JToggleButton("直线", new ImageIcon("image/shape_line.gif")); btnDrawLine.setBackground(new Color(250, 251, 252)); btnDrawLine.setSelected(true); btnDrawLine.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pCanvas.setShape(Button.LINE); } }); btnDrawLine.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode() == 127) pCanvas.deleteOnCanvas(); } }); /*Button of drawing Rectangle*/ btnDrawRectangle = new JToggleButton("矩形", new ImageIcon("image/shape_rectangle.gif")); btnDrawRectangle.setBackground(new Color(250, 251, 252)); btnDrawRectangle.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pCanvas.setShape(Button.RECTANGLE); } }); btnDrawRectangle.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode() == 127) pCanvas.deleteOnCanvas(); } }); /*Button of drawing Oval*/ btnDrawOval = new JToggleButton("椭圆", new ImageIcon("image/shape_oval.gif")); btnDrawOval.setBackground(new Color(250, 251, 252)); btnDrawOval.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pCanvas.setShape(Button.OVAL); } }); btnDrawOval.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode() == 127) pCanvas.deleteOnCanvas(); } }); /*Button of drawing Text*/ btnDrawText = new JToggleButton("文本", new ImageIcon("image/shape_text.gif")); btnDrawText.setBackground(new Color(250, 251, 252)); btnDrawText.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pCanvas.setShape(Button.TEXT); } }); btnDrawText.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub pCanvas.addText(e.getKeyChar() + "", false); } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode() == 10) pCanvas.addText("", true); else if (e.getKeyCode() == 127) pCanvas.deleteOnCanvas(); } }); /*Color picker*/ btnColor = new JButton("颜色", new ImageIcon("image/shape_color.gif")); btnColor.setBackground(new Color(250, 251, 252)); btnColor.setFocusable(false); btnColor.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub pCanvas.setColor(JColorChooser.showDialog(pCanvas, "选择颜色", new Color(0, 0, 0))); } }); /*Set the 4 button as button group*/ ButtonGroup btnGroup = new ButtonGroup(); btnGroup.add(btnDrawLine); btnGroup.add(btnDrawRectangle); btnGroup.add(btnDrawOval); btnGroup.add(btnDrawText); /*add the components into pOption Panel*/ pOption.add(btnDrawLine); pOption.add(btnDrawRectangle); pOption.add(btnDrawOval); pOption.add(btnDrawText); pOption.add(btnColor); /*Components of main panel*/ pMain.add(pOption, BorderLayout.NORTH); pMain.add(pCanvas, BorderLayout.CENTER); }