澳门新葡亰游戏网址,import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionAdapter; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JRadioButton; public class TestEventMouse extends JFrame{   Container contentPanel; //内容格引用 JButton a1,a2,a3,a4,a5;//按钮 JRadioButton backGroundRadio,foreGroundRadio;  //定义两个单选框 ButtonGroup radioGroup;  //单选按钮组 int xValue,yValue;  //保留鼠标位置(x,y) JFrame jf=this; public TestEventMouse(){ //构造函数 super(“写字板”); a1=new JButton(“Black”);//实现五个按钮 a2=new JButton(“Blue”); a3=new JButton(“Red”); a4=new JButton(“White”); a5=new JButton(“Yellow”); contentPanel=this.getContentPane();//获取内容格 contentPanel.setLayout(new FlowLayout());//设置内容格的布局管理器 backGroundRadio=new JRadioButton(“backGround”); //实例化复选框 foreGroundRadio=new JRadioButton(“foreGround”); contentPanel.add(backGroundRadio);//添加到内容格里面去 contentPanel.add(foreGroundRadio); contentPanel.add(a1);//添加按钮 contentPanel.add(a2); contentPanel.add(a3); contentPanel.add(a4); contentPanel.add(a5); MouseListenerHandler mou=new MouseListenerHandler(); //实现一个事件监听类 a1.addMouseListener(mou); //注册为五个按钮的监听者 a2.addMouseListener(mou); a3.addMouseListener(mou); a4.addMouseListener(mou); a5.addMouseListener(mou); radioGroup=new ButtonGroup(); //实例单选按钮组 radioGroup.add(backGroundRadio);//将两个radio按钮构成一个组 radioGroup.add(foreGroundRadio); addMouseMotionListener(  //匿名类 new MouseMotionAdapter(){  //因为是当前一个对象调用,所以搞了个适配器玩玩 public void mouseDragged(MouseEvent e){ xValue=e.getX(); yValue=e.getY(); repaint();  //调用paint()方法 } } ); setSize(500,500);   setVisible(true);  //设置可见 } public class MouseListenerHandler implements MouseListener{  //鼠标事件监听类 public void mousePressed(MouseEvent e){  if(e.getSource()==a1){   //用getSouce()获取对象 if(backGroundRadio.isSelected()) contentPanel.setBackground(Color.BLACK);//用内容格来设置背景色 else                                 jf.setForeground(Color.BLACK);   //用Frame框架来设置前景色 } if(e.getSource()==a2){ if(backGroundRadio.isSelected()) contentPanel.setBackground(Color.BLUE); else jf.setForeground(Color.BLUE); } if(e.getSource()==a3){ if(backGroundRadio.isSelected()) contentPanel.setBackground(Color.RED); else jf.setForeground(Color.RED); } if(e.getSource()==a4){ if(backGroundRadio.isSelected()) contentPanel.setBackground(Color.WHITE); else jf.setForeground(Color.WHITE); } if(e.getSource()==a5){ if(backGroundRadio.isSelected()) contentPanel.setBackground(Color.YELLOW); else jf.setForeground(Color.YELLOW); } } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } } public void paint(Graphics g){  g.fillOval(xValue, yValue, 4, 4);  } public static void main(String args[]){ new TestEventMouse();  } }

package UserJFrame; import java.awt.BorderLayout;import java.awt.Button;import java.awt.Color;import java.awt.Dimension;import java.awt.FileDialog;import java.awt.Font;import java.awt.GraphicsEnvironment;import java.awt.GridLayout;import java.awt.Label;import java.awt.MenuBar;import java.awt.Panel;import java.awt.TrayIcon.MessageType;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.font.TextLayout; import javax.swing.ButtonGroup;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Group;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JRadioButton;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.JToolBar;import javax.swing.LayoutStyle;import javax.swing.filechooser.FileNameExtensionFilter;import javax.swing.plaf.basic.BasicBorders.RadioButtonBorder;import javax.swing.text.StyledEditorKit.BoldAction; public class UserJFrame extends JFrame implements ActionListener, MouseListener {    private JButton btnAdd;    private JTextArea textarea;    private JRadioButton btnMan,btnFelman;    private JTextField tfdNumber,tfdName;    private JComboBox comProvince,comCitys;    private int number=1;    private Object[][] citys;    private JTextField tfd1;    private JMenuItem jmenuItemcolor[]=null;    private JDialog jdialog1,jdialogsave;    private Font font1;    private JPopupMenu jpopupmenu;    private JPanel jpanel1,jpanel2;    private JComboBox combofonename,combofonesize;    private JCheckBox checkBold,checkItalic;    private JRadioButton radioColor[];    private Font font;    public UserJFrame(Object[] province, Object[][] citys) {        super("个人信息统计");        this.citys=citys;        this.setBounds(200, 200, 650, 400);        this.getContentPane().setBackground(Color.lightGray);        this.getContentPane().setLayout(new BorderLayout;        this.setDefaultCloseOperation(EXIT_ON_CLOSE);        //设置菜单栏        addMymenu();//调用下面声明的菜单栏相关代码        jpanel1=new JPanel();//用来存放工具栏的面板        jpanel2=new JPanel();//用来搞下面的文本区和信息添加区的面板        JToolBar jtoolbar=new JToolBar();//给工具栏开空间        //以下为工具栏的内容,包括字体大小设置,字体设置,字形选择框        //获取系统字体        GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();        String fonesName[]=ge.getAvailableFontFamilyNames();        combofonename=new JComboBox(fonesName);        combofonename.addActionListener(this);//添加字体的监听        jtoolbar.add(combofonename);        //字体大小设置        String fonesSize[]={"20","30","40","50","60","70"};        combofonesize=new JComboBox(fonesSize);        combofonesize.addActionListener(this);        jtoolbar.add(combofonesize);        combofonesize.setEditable(true);        //字体选择        checkBold=new JCheckBox("粗体");        checkItalic=new JCheckBox("斜体");        jtoolbar.add(checkBold);        jtoolbar.add(checkItalic);        //颜色选择        String colorStr[]={"红","绿","蓝","黑"};        radioColor=new JRadioButton[colorStr.length];        ButtonGroup group=new ButtonGroup();        for(int i=0;i<colorStr.length;i++){            radioColor[i]=new JRadioButton(colorStr[i]);            jtoolbar.add(radioColor[i]);            group.add(radioColor[i]);            radioColor[i].addActionListener(this);        }        jpanel1.add;//工具栏加到jpanel1中        this.getContentPane().add(jpanel1, BorderLayout.NORTH);//设定jpanel1的位置并添加到整个面板中        this.getContentPane().add;//jpanel2添加进去        jpanel2.setLayout(new GridLayout;//把界面1分2,左边为文本框眼,右边为信息添加部分栏        textarea=new JTextArea();        //textarea.setEditable;   //如果有这条代码,则文本框不可编辑        jpanel2.add(new JScrollPane);        JPanel jpanel=new JPanel(new GridLayout(7, 1));        jpanel2.add;        //把各种元素加进右边面板        tfdNumber=new JTextField("1");        tfdNumber.setEditable(false);        jpanel.add(tfdNumber);                tfdName=new JTextField("姓名:");        jpanel.add;                JPanel jpanelrd=new JPanel(new GridLayout(1,2));        btnMan=new JRadioButton("男",true);        btnFelman=new JRadioButton("女");        jpanelrd.add;        jpanelrd.add(btnFelman);        jpanel.add;        ButtonGroup btngroup=new ButtonGroup();// 使其中的按键互斥,只能选择一个,所以把他们放在同一个按键组里        btngroup.add;        btngroup.add(btnFelman);        //省份组合框        comProvince=new JComboBox;        comProvince.addActionListener(this);        jpanel.add(comProvince);                comCitys=new JComboBox(citys[0]);        jpanel.add;                tfd1=new JTextField("备注:");        jpanel.add;                    btnAdd=new JButton("添加");        btnAdd.addActionListener(this);        jpanel.add;        //添加鼠标右键快捷菜单        jpopupmenu=new JPopupMenu();        String popumenuItem[]={"粘贴","复制","剪切"};        JMenuItem popumenuItemadd[]=new JMenuItem[popumenuItem.length];        for(int i=0;i<popumenuItem.length;i++){            popumenuItemadd[i]=new JMenuItem(popumenuItem[i]);            jpopupmenu.add(popumenuItemadd[i]);            popumenuItemadd[i].addActionListener(this);        }        textarea.add(jpopupmenu);        textarea.addMouseListener(this);        this.setVisible(true);    }    private void addMymenu() {        JMenuBar jmenubar=new JMenuBar();        setJMenuBar;        String menustr[]={"文件","编辑","帮助"};        JMenu menu[]=new JMenu[menustr.length];        for(int i=0;i<menustr.length;i++){            menu[i]=new JMenu(menustr[i]);            jmenubar.add;        }        //"文件"菜单的子菜单        JMenuItem open=new JMenuItem("打开");        open.setActionCommand("open");        open.addActionListener(this);        menu[0].add;        JMenuItem save=new JMenuItem("保存");        menu[0].add;                menu[0].addSeparator();                JMenuItem past=new JMenuItem("粘贴");        past.addActionListener(this);        menu[0].add;                JMenuItem copy=new JMenuItem("复制");        copy.addActionListener(this);        menu[0].add;                JMenuItem cut=new JMenuItem("剪切");        cut.addActionListener(this);        menu[0].add;                menu[0].addSeparator();                JMenuItem exit=new JMenuItem("退出");        exit.setActionCommand("exit");        exit.addActionListener(this);        menu[0].add;        //"编辑 "菜单的子菜单        JMenu wordstyle=new JMenu("字形");        menu[1].add(wordstyle);        JMenu colorstyle=new JMenu("颜色设置");        menu[1].add(colorstyle);        //设置“字形的二级菜单”        String wordstyle1[]={"粗体","斜体"};        JMenuItem jmenuitem[]=new JMenuItem[wordstyle1.length];        for(int i=0;i<wordstyle1.length;i++){            jmenuitem[i]=new JMenuItem(wordstyle1[i]);            wordstyle.add(jmenuitem[i]);            jmenuitem[i].addActionListener(this);        }        //设置“颜色设置”二级菜单        String colorstyle1[]={"红","绿","蓝","黑"};        jmenuItemcolor=new JMenuItem[colorstyle1.length];        for(int i=0;i<colorstyle1.length;i++){            jmenuItemcolor[i]=new JMenuItem(colorstyle1[i]);            colorstyle.add(jmenuItemcolor[i]);            jmenuItemcolor[i].addActionListener(this);        }                JMenuItem jmenuitemhelp=new JMenuItem("相关帮助咨询");        jmenuitemhelp.addActionListener(this);        menu[2].add(jmenuitemhelp);     }    @Override    public void actionPerformed(ActionEvent e) {        if(e.getSource()==btnAdd){            String aline;            //添加名字和编号            aline=this.number+","+tfdName.getText();            //添加性别            if(btnMan.isSelected{                aline=aline+","+btnMan.getText();            }            if(btnFelman.isSelected{                aline=aline+","+btnFelman.getText();            }            //添加省份            aline=aline+","+comProvince.getSelectedItem();                        //添加市级            aline=aline+","+comCitys.getSelectedItem();            //添加备注            aline=aline+","+tfd1.getText();            tfd1.setText("备注:");                        textarea.append(aline+"n");            this.number++;            tfdNumber.setText(""+this.number);            tfdName.setText("姓名:");                    }                else if(e.getSource()==comProvince){            int i=comProvince.getSelectedIndex();            comCitys.removeAllItems();            System.out.println(citys[i].length);            for(int j=0;j<citys[i].length;j++){                comCitys.addItem(citys[i][j]);            }        }        else if(e.getSource() instanceof JMenuItem||e.getSource() instanceof JRadioButton){            //设置颜色的监听            Color color=null;  //用传参的思维做颜色            if(e.getActionCommand().equals("红")){                color=new Color(255,0,0);            }            if(e.getActionCommand().equals("绿")){                color=new Color(0,255,0);            }            if(e.getActionCommand().equals("蓝")){                color=new Color(0,0,255);            }            if(e.getActionCommand().equals("黑")){                color=new Color(0,0,0);            }            textarea.setForeground;            //设置帮助的监听            if(e.getActionCommand().equalsIgnoreCase("相关帮助咨询")){                jdialog1=new JDialog(this,true);                jdialog1.setSize(330, 100);                int lx=getX()+20;                int ly=getY()+20;                jdialog1.setLocation;                jdialog1.add(new Label("相关帮助请咨询电话10010,最终解释权归联通公司所有!"));                jdialog1.setVisible(true);            }            //设置字形的监听            if(e.getActionCommand().equals("粗体")){                font1=new Font,20, 20);                textarea.setFont;            }            if(e.getActionCommand().equals("斜体")){                            }            //退出的监听            if(e.getActionCommand().equalsIgnoreCase("exit")){                int option=JOptionPane.showConfirmDialog(this, "你确定保存并退出么?");                if(option==JOptionPane.OK_OPTION){                    System.out.println("保存中...");                    System.exit(0);                }                if(option==JOptionPane.NO_OPTION){                    System.exit(0);                }                if(option==JOptionPane.CANCEL_OPTION){                    return;                }                            }            //保存的监听            if(e.getActionCommand().equalsIgnoreCase("复制")){                textarea.copy();            }            //粘贴监听            if(e.getActionCommand().equalsIgnoreCase("粘贴")){                textarea.paste();            }            //剪切监听            if(e.getActionCommand().equalsIgnoreCase("剪切")){                textarea.cut();            }            //打开的监听            if(e.getActionCommand().equals("open")){                openFile();            }                }    //字形的监听        /*if(e.getSource() instanceof JComboBox ){                String fontName= combofonename.getSelectedItem();                int fontSize=0;                String strSize= combofonesize.getSelectedItem();                int style = changeStyle;                font=new Font(fontName, style, fontSize);                textarea.setFont;        }    }    private int changeStyle(ActionEvent e) {    // TODO Auto-generated method stub    return 0;*/    }    private void openFile() {        FileDialog openFileDlg = new FileDialog(this, "打开文件", FileDialog.LOAD);        openFileDlg.setVisible(true);}        @Override    public void mouseClicked(MouseEvent e) {        if(e.getModifiers()==MouseEvent.BUTTON3_MASK){            jpopupmenu.show(textarea,e.getX(), e.getY;        }    }    public void mousePressed(MouseEvent e) {    }    public void mouseReleased(MouseEvent e) {    }    public void mouseEntered(MouseEvent e) {    }    public void mouseExited(MouseEvent e) {    }    public static void main(String[] args) {        Object province[]={"四川省","湖南省","江苏省"};        Object citys[][]={{"成都市","遂宁市","南充市","德阳市","绵阳市"},                          {"益阳市","长沙市","株洲市","湘潭市","岳阳市"},                          {"南京市","苏州市","无锡市"}        };        new UserJFrame(province,citys);    }}

网站地图xml地图