• 大小: 1.14MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-11
  • 语言: Java
  • 标签:

资源简介

22份java图形用户界面代码,附带详细说明,有利于初学者学习java图形用户界面

资源截图

代码片段和文件信息

package pack1;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Jframe;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
public class JPopupMenuTest extends Jframe {
    private static final long serialVersionUID = -6359250625337227762L;
    JPopupMenu pop = new JPopupMenu();
    Color bc;
    JMenu f = new JMenu(“背景颜色“);
    JMenuItem item1= new JMenuItem(“红色“);
    JMenuItem item2= new JMenuItem(“绿色“);
    JMenuItem item3= new JMenuItem(“蓝色“);
    JPanel panel;
    public JPopupMenuTest() {
     settitle(“弹出式菜单演示“);
        setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
        setSize(new Dimension(240 240));
        setVisible(true);
        panel = new JPanel();
        panel.setBackground(new Color(12030100));
        f.add(item1); f.add(item2); f.add(item3);
        pop.add(f);
        item1.addActionListener(new koActionListener());
        item2.addActionListener(new koActionListener());
        item3.addActionListener(new koActionListener());

        panel.setComponentPopupMenu(pop);
        this.setLayout(new BorderLayout());
        this.add(panel BorderLayout.CENTER);
    }
     public static void main(String[] args) {
        new JPopupMenuTest();
    }
     class koActionListener implements ActionListener
  {
  public void actionPerformed(ActionEvent e)
     {
      String ko=e.getActionCommand();
      if (ko.equals(item1.getText()))
       bc=Color.red;
      else if (ko.equals(item2.getText()))
       bc=Color.green;
      else if (ko.equals(item3.getText()))
       bc=Color.blue;
       panel.setBackground(bc);
     }
  }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-07 16:21  lesson7\
     文件         346  2015-11-12 16:33  lesson7\.classpath
     文件         383  2015-10-23 10:47  lesson7\.project
     目录           0  2018-11-07 16:21  lesson7\.settings\
     文件         598  2015-10-23 10:48  lesson7\.settings\org.eclipse.jdt.core.prefs
     目录           0  2018-11-25 12:31  lesson7\bin\
     文件        1763  2000-07-12 17:03  lesson7\bin\img0001.gif
     文件        1743  2000-07-12 17:03  lesson7\bin\img0002.gif
     文件        1741  2000-07-12 17:03  lesson7\bin\img0003.gif
     文件        1702  2000-07-12 17:03  lesson7\bin\img0004.gif
     文件        1687  2000-07-12 17:03  lesson7\bin\img0005.gif
     文件        1719  2000-07-12 17:03  lesson7\bin\img0006.gif
     文件        1726  2000-07-12 17:03  lesson7\bin\img0007.gif
     文件        1708  2000-07-12 17:03  lesson7\bin\img0008.gif
     文件        1737  2000-07-12 17:03  lesson7\bin\img0009.gif
     文件        1747  2000-07-12 17:03  lesson7\bin\img0010.gif
     文件        1759  2000-07-12 17:03  lesson7\bin\img0011.gif
     文件        1729  2000-07-12 17:03  lesson7\bin\img0012.gif
     文件        1714  2000-07-12 17:03  lesson7\bin\img0013.gif
     文件        1714  2000-07-12 17:03  lesson7\bin\img0014.gif
     文件        1729  2000-07-12 17:03  lesson7\bin\img0015.gif
     文件        1747  2000-07-12 17:03  lesson7\bin\img0016.gif
     文件        1759  2000-07-12 17:03  lesson7\bin\img0017.gif
     文件        1739  2000-07-12 17:03  lesson7\bin\img0018.gif
     目录           0  2018-11-25 12:31  lesson7\bin\pack1\
     文件      328128  2012-10-30 12:48  lesson7\bin\pack1\audio1.au
     文件       28144  2010-05-09 10:11  lesson7\bin\pack1\audiotest.au
     文件      216364  2009-06-11 04:40  lesson7\bin\pack1\chimes.wav
     文件      113964  2009-06-11 04:40  lesson7\bin\pack1\chord.wav
     文件        1368  2018-11-25 12:31  lesson7\bin\pack1\JPopupMenuTest$koActionListener.class
     文件        2103  2018-11-25 12:31  lesson7\bin\pack1\JPopupMenuTest.class
............此处省略87个文件信息

评论

共有 条评论