在我目前正在进行的项目中,我希望通过 Jlabel 显示几条信息。GUI 中的其他位置有一些按钮和文本字段,允许更改所述信息,我想更新 JLabel,但文本永远不会更改,或在启动时更新。
我尝试使用并发来更新标签,正如本网站上其他问题中所建议的那样,但我在标签更新方面没有运气。并发确实可以根据需要更新文本字段和组合框。
我的代码的当前迭代如下所示,
J框架
//// This is a snippet from the JFrame
public void start()
{
this.setSize(900, 700);
this.setVisible(true);
devicePanel.populateDeviceDefinitions();
updateServiceInfo();
updateCommandInfo();
startUpdateTimer();
}
public void updateServiceInfo()
{
EventService service = JetstreamApp.getService();
generalPanel.updateServiceInfo(service.getBaseUri(),
service.getAccessKey(), String.valueOf(service.getWindowTime()));
}
public void updateCommandInfo()
{
JetstreamServiceClient client = JetstreamApp.getClient();
generalPanel.updateCommandInfo(client.getBaseUri(), client.getAccessKey());
}
Run Code Online (Sandbox Code Playgroud)
名为 GeneralPanel 的 JPanel
//// This is a snippet from the generalPanel
//// All of the variables in the following code are JLabels
public void updateServiceInfo(String baseUrl, String accessKey, …Run Code Online (Sandbox Code Playgroud) 我目前正在使用CentOS 5.8,我想将g ++更新到最新版本.我目前的g ++版本是4.1.2,当我尝试更新它时说我已经使用了最新版本.
有没有办法强制更新到当前版本?
我无法使用抽象类作为值来正确编译抽象类.理想情况下,我想做类似以下的事情
unordered_map<string, Process_Base> func_map;
Run Code Online (Sandbox Code Playgroud)
Process_Base的样子
//Contained in Process_Base.hpp
class Process_Base{
public:
virtual ~Process_Base(){};
virtual void process() const = 0;
};
Run Code Online (Sandbox Code Playgroud)
和子类看起来像
#include "Process_Base.hpp"
class Process_Message : public Process_Base {
public:
~Process_Message(){};
virtual void process();
};
#include <stdio.h>
#include <string.h>
#include "Process_Base.hpp"
class Process_Message{
public:
void process(){
printf("%s", "Hello");
}
};
Run Code Online (Sandbox Code Playgroud)
这背后的想法是我能够在地图中添加子类,并有一个简单的函数,它将查看一个键值并调用子类的进程函数.
当我在CentOS 5.8上编译时使用
g++44 -Wall -c -std=c++0x -I/usr/include -g Source.cpp
Run Code Online (Sandbox Code Playgroud)
我得到以下一系列错误
In file included from /usr/lib/gcc/x86_64-redhat-linux6E/4.4.6/../../../../include/c++/4.4.6/bits/stl_algobase.h:66,
from /usr/lib/gcc/x86_64-redhat-linux6E/4.4.6/../../../../include/c++/4.4.6/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-redhat-linux6E/4.4.6/../../../../include/c++/4.4.6/string:42,
from Source.cpp:2:
/usr/lib/gcc/x86_64-redhat-linux6E/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h: In instantiation of ‘std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> …Run Code Online (Sandbox Code Playgroud) 我试图创建一个强大的头文件,将在Windows和Linux上编译而无需更改.为此,我在我的包含中有一个if语句
#if (!defined(__WINDOWS__))
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#endif
Run Code Online (Sandbox Code Playgroud)
尽管if语句导致错误,我仍然遇到Visual Studio仍然试图包含这些标题的问题
error C1083: Cannot open include file: 'sys/time.h'
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题,而无需从头文件中删除所有linux代码块?
我对java中的代码效率有疑问.我目前有一个类似于以下方法
public class Response extends SuperResponse {
private Object ConfigureResponse = null;
public String getId() {
if(this.getBody() == null || this.getBody().isEmpty()) {
return null;
} else {
// Check if the ConfigureResponse has already been deserialized
// if it has, there is no need to deserialize is again
if(ConfigureResponse == null) {
ConfigureResponse = JAXB.unmarshal(new StringReader(
this.getBody()), Object.class);
}
return ConfigureResponse.getConfigureResponse().getId();
}
}
}// End class
Run Code Online (Sandbox Code Playgroud)
如果重复调用该getId方法,最好保存Id字符串并直接返回,并保存自己的方法调用以返回它吗?或者Java编译器是否足够智能以直接转换这些方法调用.
我有一个简单的示例代码
#include <string>
#include <stdio.h>
#include <iostream>
int main ()
{
std::cout << "Connecting to hello world server…" << std::endl;
printf ("Connecting to hello world server...\n");
while(true)
{
}
}
Run Code Online (Sandbox Code Playgroud)
在控制台窗口中,第一行将椭圆打印为"a"字符,其上方有一个波浪号,第二行按预期打印.
有人可以解释为什么会这样吗?
我想迭代一个struct指针的向量,并在每个上做一些工作.在使用谷歌和这个网站研究这个问题后,我一直在尝试使用以下代码,但是没有运气获得编译代码.
我使用的循环如下,我尝试了两种类型
for (auto & i : Mg_Server::servers)
{
printf("%s\n", i->server_ctx->ns_server->server_data);
}
/*
for (vector<Mg_Server::mg_instance *>::size_type i = 0; i != Mg_Server::servers.size; ++i)
{
printf("%s\n", Mg_Server::servers[i]->server_ctx->ns_server->server_data);
}*/
Run Code Online (Sandbox Code Playgroud)
我的向量在头文件中声明为静态
class Mg_Server {
public:
Mg_Server(){}
~Mg_Server(){}
// functions
private:
struct mg_instance{
struct mg_server * server_ctx;
bool running;
};
// stuff
static vector<mg_instance *> servers;
};
Run Code Online (Sandbox Code Playgroud)
我已经使用了cpp文件中的向量实例化
vector<Mg_Server::mg_instance *> Mg_Server::servers;
Run Code Online (Sandbox Code Playgroud)
我正在使用CentOS 5.8编译此代码
g++44 -Wall -c -std=c++0x "some include directories" -g -D LINUX -m64 -ansi src/mg_server.cpp
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.第58行是for语句在for循环后开始的地方.
src/mg_server.cpp:47: warning: ‘auto’ will change meaning in …Run Code Online (Sandbox Code Playgroud) 我已经为Java的TreeSet函数创建了一个比较器类,我希望用它来命令消息.这个类看起来如下
public class MessageSentTimestampComparer
{
/// <summary>
/// IComparer implementation that compares the epoch SentTimestamp and MessageId
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public int compare(Message x, Message y)
{
String sentTimestampx = x.getAttributes().get("SentTimestamp");
String sentTimestampy = y.getAttributes().get("SentTimestamp");
if((sentTimestampx == null) | (sentTimestampy == null))
{
throw new NullPointerException("Unable to compare Messages " +
"because one of the messages did not have a SentTimestamp" +
" Attribute");
}
Long epochx = Long.valueOf(sentTimestampx);
Long epochy = Long.valueOf(sentTimestampy); …Run Code Online (Sandbox Code Playgroud) 我正在讨论一个侧面项目的一些想法,我想创建一个使用Java swing的GUI,它看起来不像来自Windows95.我正在努力的一个想法是使用JLabel作为按钮而不是标准的JButton.这样我就可以根据需要自定义悬停,拖动和移动效果.
研究MouseAdapter class应该允许我做我想做的一切,不幸的是我在实现悬停效果时遇到了一些麻烦,因为它JLabel似乎没有更新.我已经尝试通过调用直接更新帧,frame.update(getGraphics());但这似乎不像我认为的那样工作.
我可以就如何正确更新标签获得一些建议.
注意:这只是一个示例,没有花费精力来有效地组织代码
public class Window extends JFrame {
/**
*
*/
private static final long serialVersionUID = 5259700796854880162L;
private JTextField textField;
private JLabel lblNewLabel;
static Window frame;
int i = 0;
public Window() {
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
lblNewLabel = new JLabel("New label");
lblNewLabel.setBackground(Color.LIGHT_GRAY);
lblNewLabel.setBounds(137, 38, 114, 70);
panel.add(lblNewLabel);
lblNewLabel.addMouseListener(new LabelAdapter());
textField = new JTextField();
textField.setBounds(122, 119, 86, 20);
panel.add(textField);
textField.setColumns(10);
}
private class LabelAdapter extends …Run Code Online (Sandbox Code Playgroud) 我将 Angular Material 的表格与 Bootstrap 的声明性 css 一起使用。尽管将表格的宽度和最大宽度设置为 100%,但一列无法正确截断文本。当未设置容器的宽度时,通常会出现此问题。我应该在 Material 表上应用哪些类来截断长文本。
<div class="col flex-grow-1 min-height-0 m-0 p-0">
<div class="h-100 overflow-auto">
<table *ngIf="trunks | async as data" mat-table
[dataSource]="data.entities"
class="w-100">
<ng-container matColumnDef="select">
... Checkbox logic
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>
... Header logic, this is much shorter than the offending name
</ng-container>
</th>
<td mat-cell *matCellDef="let trunk" class="text-truncate">
<div class="d-inline text-truncate">
... Status icon logic, width of < 40px
<a [routerLink]="['./' + trunk.id]" [queryParams]="{}" queryParamsHandling="merge"
class="text-truncate">{{ trunk.name }}</a>
</div>
</td> …Run Code Online (Sandbox Code Playgroud) 我有一系列C#代码,我试图用Java复制.代码如下所示.
n.InnerText = DateTime.Parse(n.InnerText).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
Run Code Online (Sandbox Code Playgroud)
目的是将xml上下文中的DateTime替换为表示通用时间的DateTime.
我试图使用
node.setTextContent = Date.parse(node.getTextContent())
Run Code Online (Sandbox Code Playgroud)
但由于不推荐使用Date.parse(),我无法继续.我阅读了Eclipse中的注释,并按照建议尝试了DateFormat,但是DateFormat没有解析方法.
有人可以建议我的问题的解决方案,不使用任何第三方库?