• 关于

    windowevent

    的搜索结果

问题

聊天小程序客户端不能向服务器端发信息如何解决? 400 报错

聊天小程序客户端不能向服务器端发信息如何解决? 400 报错 小程序客户端: import java.awt.*;import java.awt.event.*; import javax.swing.*; impo...
爱吃鱼的程序员 2020-06-03 16:36:09 2 浏览量 回答数 1

问题

java程序出现Exception in thread "main" java.?报错

java程序出现Exception in thread "main" java.lang.Error: Unresolved compilation problem: at src.TankClient.main(TankC...
优选2 2020-06-09 15:28:55 6 浏览量 回答数 1

问题

java程序出现Exception in thread "main" java.?400报错

java程序出现Exception in thread "main" java.lang.Error: Unresolved compilation problem: at src.TankClient.main(TankC...
爱吃鱼的程序员 2020-05-30 13:56:18 1 浏览量 回答数 1

阿里云试用中心,为您提供0门槛上云实践机会!

100+款试用云产品,最长免费试用12个月!拨打95187-1,咨询专业上云建议!

问题

OpenJDK8编译后遇到字体绘制问题? 400 报错

OpenJDK8编译后遇到字体绘制问题? 400 报错 用OpenJDK8最新版本开源代码 + Win7环境,编译OpenJDK8版本,字体用宋体,分别在16榜时倾斜,缩放&...
爱吃鱼的程序员 2020-05-30 21:11:53 0 浏览量 回答数 1

问题

自己写的Client端提示空指针问题

public class ChatClient { static Socket s; static DataOutputStream dos; static String str; static TextField txt; static ...
蛮大人123 2019-12-01 20:25:46 713 浏览量 回答数 1

回答

class JTableButtonRenderer implements TableCellRenderer { private TableCellRenderer __defaultRenderer; public JTableButtonRenderer(TableCellRenderer renderer) { __defaultRenderer = renderer; } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value instanceof Component) return (Component) value; return __defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } } class JTableButtonModel extends AbstractTableModel { private Object[][] __rows = { { "One", new JButton("Button One") }, { "Two", new JButton("Button Two") }, { "Three", new JButton("Button Three") }, { "Four", new JButton("Button Four") } }; private String[] __columns = { "Numbers", "Buttons" }; public String getColumnName(int column) { return __columns[column]; } public int getRowCount() { return __rows.length; } public int getColumnCount() { return __columns.length; } public Object getValueAt(int row, int column) { return __rows[row][column]; } public boolean isCellEditable(int row, int column) { return false; } public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } } class JTableButtonMouseListener implements MouseListener { private JTable __table; private void __forwardEventToButton(MouseEvent e) { TableColumnModel columnModel = __table.getColumnModel(); int column = columnModel.getColumnIndexAtX(e.getX()); int row = e.getY() / __table.getRowHeight(); Object value; JButton button; MouseEvent buttonEvent; if (row >= __table.getRowCount() || row < 0 || column >= __table.getColumnCount() || column < 0) return; value = __table.getValueAt(row, column); if (!(value instanceof JButton)) return; button = (JButton) value; buttonEvent = (MouseEvent) SwingUtilities.convertMouseEvent(__table, e, button); button.dispatchEvent(buttonEvent); // This is necessary so that when a button is pressed and released // it gets rendered properly. Otherwise, the button may still appear // pressed down when it has been released. __table.repaint(); } public JTableButtonMouseListener(JTable table) { __table = table; } public void mouseClicked(MouseEvent e) { __forwardEventToButton(e); } public void mouseEntered(MouseEvent e) { __forwardEventToButton(e); } public void mouseExited(MouseEvent e) { __forwardEventToButton(e); } public void mousePressed(MouseEvent e) { __forwardEventToButton(e); } public void mouseReleased(MouseEvent e) { __forwardEventToButton(e); } } -------------------------------------------- import java.awt.Dimension; import java.awt.Frame; import java.awt.Window; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.*; import javax.swing.table.TableCellRenderer; public final class JTableButton extends JFrame { private JTable __table; private JScrollPane __scrollPane; public JTableButton() { super("JTableButton Demo"); TableCellRenderer defaultRenderer; __table = new JTable(new JTableButtonModel()); defaultRenderer = __table.getDefaultRenderer(JButton.class); __table.setDefaultRenderer(JButton.class, new JTableButtonRenderer( defaultRenderer)); __table.setPreferredScrollableViewportSize(new Dimension(400, 200)); __table.addMouseListener(new JTableButtonMouseListener(__table)); __scrollPane = new JScrollPane(__table); setContentPane(__scrollPane); } public static void main(String[] args) { Frame frame; WindowListener exitListener; exitListener = new WindowAdapter() { public void windowClosing(WindowEvent e) { Window window = e.getWindow(); window.setVisible(false); window.dispose(); System.exit(0); } }; frame = new JTableButton(); frame.addWindowListener(exitListener); frame.pack(); frame.setVisible(true); } }
蛮大人123 2019-12-02 02:28:50 0 浏览量 回答数 0

回答

class TreesDemo extends JFrame implements TreeSelectionListener { JTree tree=null; JTextArea text=new JTextArea(20,20); public TreesDemo() { super("处理结点事件"); Container con=getContentPane(); String[][] data={ {"我的电脑","本机磁盘(C:)","本机磁盘(D:)","本机磁盘(E:)"}, {"收藏夹","思维论坛","Java爱好者","网上书店"}, {"我的公文包","公司文件","私人文件","往来信件"}, }; DefaultMutableTreeNode root; DefaultMutableTreeNode treeNode[][]; root=new DefaultMutableTreeNode("桌面"); treeNode=new DefaultMutableTreeNode[4][4]; for(int i=0;i<data.length;i++) { treeNode[i][0]=new DefaultMutableTreeNode(data[i][0]); root.add(treeNode[i][0]); for(int j=1;j<4;j++) { treeNode[i][0].add(new DefaultMutableTreeNode(data[i][j])); } } tree=new JTree(root); JScrollPane scrollpane=new JScrollPane(text); JSplitPane splitpane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,tree,scrollpane); con.add(splitpane); tree.addTreeSelectionListener(this); setSize(500,200); setVisible(true); validate(); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } public void valueChanged(TreeSelectionEvent e) { if(e.getSource()==tree) { DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); if(node.isLeaf()) { String str=node.toString(); if(str.equals("本机磁盘(C:)")) { text.setText(str+":\n这里显示‘C:盘文件'"); } else if(str.equals("本机磁盘(D:)")) { text.setText(str+":\n这里显示‘D:盘文件'"); } else if(str.equals("思维论坛")) { text.setText(str+":\n这里显示‘www.zsm8.com的精华帖子'"); } else if(str.equals("Java爱好者")) { text.setText(str+":\n这里显示‘Java爱好者网站'"); } else if(str.equals("网上书店")) { text.setText(str+":\n这里显示‘网上书店的购物信息'"); } else if(str.equals("公司文件")) { text.setText(str+":\n这里显示‘公司内部文件'"); } } else { text.setText(node.getUserObject().toString()); } } } } public class Example5_28 { public static void main(String[] args) { new TreesDemo(); } } 首先建立结构树,然后设置监听器,在监听器中设置相应的动作。程序仅供参考。
蛮大人123 2019-12-02 02:12:19 0 浏览量 回答数 0

云产品推荐

上海奇点人才服务相关的云产品 小程序定制 上海微企信息技术相关的云产品 国内短信套餐包 ECS云服务器安全配置相关的云产品 开发者问答 阿里云建站 自然场景识别相关的云产品 万网 小程序开发制作 视频内容分析 视频集锦 代理记账服务 阿里云AIoT