使用Java的Stack的GUI(GUI of Stack using Java)
我正在使用Java制作Stack的GUI。 这是我的代码
private void StackActionPerformed(java.awt.event.ActionEvent evt) { b1=new JButton("Push"); b2=new JButton("Pop"); b3=new JButton("Peek"); b4=new JButton("Clear"); b1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pushButtonActionPerformed(evt); } }); tb.add(b1); tb.add(b2); tb.add(b3); tb.add(b4); frame_st.add(tb); frame_st.setExtendedState(Frame.MAXIMIZED_BOTH); }
在这里,我将按钮添加到我的toolBar(tb)一切正常。 我没有收到任何错误。 但编译后我没有得到理想的结果。 toolBar(tb)无法添加按钮(b1,b2等)
I am making a GUI of Stack using Java. Here is my code
private void StackActionPerformed(java.awt.event.ActionEvent evt) { b1=new JButton("Push"); b2=new JButton("Pop"); b3=new JButton("Peek"); b4=new JButton("Clear"); b1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pushButtonActionPerformed(evt); } }); tb.add(b1); tb.add(b2); tb.add(b3); tb.add(b4); frame_st.add(tb); frame_st.setExtendedState(Frame.MAXIMIZED_BOTH); }
Here I am adding buttons to my toolBar (tb) everything is working fine . I am not getting any error. But after compiling am not getting the desired result . toolBar(tb) is not able to add the buttons (b1,b2,etc)
原文:https://stackoverflow.com/questions/11107093
最满意答案
使用
HashSet<T>
:HashSet类提供高性能集合操作。 集合是一个不包含重复元素的集合,其元素没有特定的顺序
HashSet<T>
甚至公开了一个接受IEnumerable<T>
的构造函数 。 通过将List<T>
传递给HashSet<T>'s
构造函数,您将得到对新HashSet<T>
的引用,该HashSet<T>
将包含原始List<T>
的不同项目序列。Use a
HashSet<T>
:The HashSet class provides high performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order
HashSet<T>
even exposes a constructor that accepts anIEnumerable<T>
. By passing yourList<T>
to theHashSet<T>'s
constructor you will end up with a reference to a newHashSet<T>
that will contain a distinct sequence of items from your originalList<T>
.
相关问答
更多-
检查会话是否存在(Check for existence of sessions)[2021-09-28]
如果您的意思是“如何查看所有会话”,这取决于所使用的会话存储机制。 您通常可以在/ tmp中找到存储为单个文件的基于文件的会话数据(或者更确切地说,如果session.save_handler是'files',则路径由session.save_path设置) 如果您的意思是“我怎样才能看到会话中的所有变量”,您可以使用foreach foreach($_SESSION as $name=>$value) { echo "$name = $value
"; } If you mean, "h ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
检查sys.xml_schema_collections : IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'MySchema') Check sys.xml_schema_collections: IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'MySchema')
-
检查属性的存在是最好的方法?(Which is the best way to check for the existence of an attribute? [duplicate])[2023-11-17]
没有“最好”的方式,因为你永远不会只是检查一个属性是否存在; 它总是一些较大的程序的一部分。 有几种正确的方法和一个显着的错误方式。 错误的方法 if 'property' in a.__dict__: a.property 这是一个演示,显示这种技术失败: class A(object): @property def prop(self): return 3 a = A() print "'prop' in a.__dict__ =", 'prop' in a. ... -
密钥存在检查HashMap(Key existence check in HashMap)[2022-11-04]
你有没有存储空值? 如果没有,你可以做: Foo value = map.get(key); if (value != null) { ... } else { // No such key } 否则,你可以检查存在,如果你得到一个null值返回: Foo value = map.get(key); if (value != null) { ... } else { // Key might be present... if (map.containsKey(key ... -
使用整数集合检查存在的最高效方法是什么?(What is the most performant way to check for existence with a collection of integers?)[2022-07-24]
使用HashSet: HashSet类提供高性能集合操作。 集合是一个不包含重复元素的集合,其元素没有特定的顺序 HashSet 甚至公开了一个接受IEnumerable 的构造函数 。 通过将List 传递给HashSet 's构造函数,您将得到对新HashSet 的引用,该HashSet 将包含原始List 的不同项目序列。 Use a HashSet : The HashSet class provides high performance set operat ... -
字典查找速度快于列表搜索。 另外一set将是一个选项。 这就是说: 如果“一堆”意味着“这将是一个50%的性能提升”,那就去做吧。 如果它不能让代码更好地阅读,那就去做吧。 如果你喜欢这样做并且没有任何坏处,那就去做吧。 否则,这很可能不值得。 Dictionary lookups are faster the list searches. Also a set would be an option. That said: If "a bunch of times" means "it would be a ...
-
转换成一套和做in是最快的方法。 if i in set(mylist): 一个集合基本上是一个哈希表,并且查找是O(1)。 Converting to a set and doing in is the fastest way. if i in set(mylist): A set is basically a hash table, and lookups are O(1).
-
访问器方法创建一种检查元素是否存在的方法。 例如,当您包括: span(:partner_flag, class: 'content-partner-flag') 然后方法: partner_flag? 如果元素存在则返回true,如果元素不存在,则返回false。 您可以在check_element_not_exist方法中调用此方法: def check_element_not_exist(page_object) page_object = page_object.downcase.gsub( ...
-
实现这只是检查无效: DocumentSnapshot document = task.getResult(); if (document != null) { Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData()); //Do the registration } else { Log.d(TAG, "No such document"); } 此Task的结果是DocumentSnapshot 。 是 ...