小编Alo*_*ius的帖子

Java JPanel有两个边框,颜色不同?

对于我的布局我希望有双边框,在我的JPanel的底部,一个应该稍暗,另一个应该稍微更轻.

目前我有1个边框:

JPanel pnlTop = new JPanel(new BorderLayout()) {
    protected void paintComponent(Graphics grphcs) {
        super.paintComponent(grphcs);
        Graphics2D g2d = (Graphics2D) grphcs;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        GradientPaint gp = new GradientPaint(0, 0,
                new java.awt.Color(237, 237, 237), 0, getHeight(),
                new java.awt.Color(222, 222, 222));
        g2d.setPaint(gp);
        g2d.fillRect(0, 0, getWidth(), getHeight()); 
    }
};
pnlTop.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(173, 173, 166)));
pnlTop.setPreferredSize(new Dimension(2000, 90));
add(pnlTop, BorderLayout.PAGE_START);
Run Code Online (Sandbox Code Playgroud)

我怎么能在我已经拥有的那个下面添加另一个边框?这可能吗?

java swing border

8
推荐指数
1
解决办法
6711
查看次数

在浏览器重新加载/关闭浏览器/退出页面之前执行Javascript功能?

有没有办法在用户选择重新加载/关闭浏览器/退出页面之前执行某个功能?

我需要这个用于我想写的"在线/离线"状态功能.我想检测用户是否仍在页面上.

有任何想法吗?:)

也许有更好的方法呢?

javascript

7
推荐指数
1
解决办法
1万
查看次数

从我的故事板上的另一个视图中获取tabbarcontroller

在我的代表中,我试图选择我的,TabBarController以便我可以用不同的背景设计它.但是问题是我TabBarController不在rootView上.

我目前的代码:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
Run Code Online (Sandbox Code Playgroud)

在我的界面构建器中,我的TabBarController设置有一个Segue名称:mainView(这是它所在的TabBarController位置).

我怎么能选择我的TabBarController

objective-c storyboard uitabbarcontroller ios

7
推荐指数
2
解决办法
2万
查看次数

当用户从计算机空闲时QT跟踪?

我试图弄清楚如何跟踪用户何时从计算机闲置,这不仅意味着我的应用程序.原因是我希望我的应用程序能够在一定时间后将用户设置为"离开".想像Skype那样在X分钟后将你带走.

任何想法如何实现这一目标?

编辑

我到目前为止跟踪鼠标的方法:

    //Init
    mouseTimer = new QTimer();
    mouseLastPos = QCursor::pos();
    mouseIdleSeconds = 0;

    //Connect and Start
    connect(mouseTimer, SIGNAL(timeout()), this, SLOT(mouseTimerTick()));
    mouseTimer->start(1000);

void MainWindow::mouseTimerTick()
{
    QPoint point = QCursor::pos();
    if(point != mouseLastPos)
        mouseIdleSeconds = 0;
    else
        mouseIdleSeconds++;

    mouseLastPos = point;

    //Here you could determine whatever to do
    //with the total number of idle seconds.

    qDebug() << mouseIdleSeconds;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法添加键盘呢?

qt

6
推荐指数
2
解决办法
1829
查看次数

NodeJS 100%cpu使用率 - epoll_wait

我试图追查为什么我的nodejs应用程序突然使用100%的CPU.该应用程序有大约50个并发连接,并在ec2微实例上运行.

以下是输出: strace -c node server.js

^C% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 87.32    0.924373           8    111657           epoll_wait
  6.85    0.072558           3     22762           pread
  2.55    0.026965           0    146179           write
  0.92    0.009733           0    108434         1 futex
  0.44    0.004661           0     82010         7 read
  0.44    0.004608           0    223317           clock_gettime
  0.31    0.003244           0    172467           gettimeofday
  0.31    0.003241          35        93           brk
  0.20    0.002075           0     75233         3 epoll_ctl
  0.19    0.002052           0     23850     11925 accept4
  0.19    0.001997           0     12302           close
  0.19    0.001973 …
Run Code Online (Sandbox Code Playgroud)

node.js

6
推荐指数
1
解决办法
2654
查看次数

NodeJS将命令行参数永久传递

我试图永远传递命令行参数,我想在我的应用程序中解析.

目前我正在开始我的应用程序:

forever start -c "node --max-old-space-size=8192 --nouse-idle-notification" /home/ubuntu/node/server.js
Run Code Online (Sandbox Code Playgroud)

我希望能够在server.js中读取一些参数.

我的阅读代码:

var arguments = process.argv.slice(2);
console.log(arguments[0]);

if(!arguments[0]) {
    console.log("Error: Missing port.");
    process.exit(1);
}
Run Code Online (Sandbox Code Playgroud)

但是我怎么告诉forever传递可以在里面读取的参数server.js

node.js

6
推荐指数
1
解决办法
4319
查看次数

Redis lua何时真正使用它?

我已经开始研究和玩lua了一下,并且发现在想要获取按键范围时它很棒.例如:

business:5:visits:2013-11-12
business:5:visits:2013-11-13
etc
Run Code Online (Sandbox Code Playgroud)

使用lua我只需要向redis发送一个命令而不是完整的日期范围.

现在我正在考虑转换更多逻辑并将其移至Redis上.

采取我们的消息存储过程,目前看起来像这样:

// create a new unique id
redisClient.incr(Config.messageId, function(err, reply) {
    var messageId = reply.toString();
    var timestmp = Date.now();

    // push message
    redisClient.zadd(Config.history + ':' + obj.uid + ':' + obj.channel.replace(/\s+/g, ''), timestmp, messageId);

    // store the message data by messageId
    redisClient.hmset(Config.messageHash + ':' + messageId, {
        'user_id': obj.uid,
        'text_body': "some text",
        'text_date': timestmp,
    });


    // set expires
    redisClient.expire(Config.history + ':' + obj.uid + ':' + obj.channel.replace(/\s+/g, ''), Config.messageExpire);
    redisClient.expire(Config.messageHash + ':' + messageId, …
Run Code Online (Sandbox Code Playgroud)

lua redis

6
推荐指数
5
解决办法
1万
查看次数

没有jQuery的onKeyUp?

我想在不使用jQuery的情况下按下enter时捕获onKeyUp.

我目前的代码是:

$('#chatboxtextarea').on('keyup', function (e) {
        var msg = document.getElementById('chatboxtextarea').value;
        if (msg.replace(/\r/g, '\\\\r').replace(/\n/g, '') != "" && e.keyCode == 13) {
            var textarea = document.getElementById('chatboxtextarea');
            textarea.value = '';

            .....code to send.....


        } else if (msg.replace(/\r/g, '\\\\r').replace(/\n/g, '') == '') {
            var textarea = document.getElementById('chatboxtextarea');
            textarea.value = '';
        }
    });
Run Code Online (Sandbox Code Playgroud)

如何在常规JavaScript中完成?

javascript jquery

5
推荐指数
1
解决办法
4378
查看次数

Nodejs:此套接字已关闭

我在Node.js中使用tcp套接字与Java客户端进行通信.

请参阅下面的基本服务器实现:

var server = my_http.createServer();
echo.installHandlers(server, {
    prefix: '/echo'
});
server.listen(8000, '0.0.0.0');

var socketServer = net.createServer(function (socket) {

    // Identify this client
    socket.name = socket.remoteAddress + ":" + socket.remotePort

    // Put this new client in the list
    clients.push(socket);

    sockets[socket.name] = socket;

    // Handle incoming messages from clients.
    socket.on('data', function (data) {

        try {
            var obj = JSON.parse(data);

            if (obj.type == "sendMessage") {
                broadcast("{\"id\":\"1\", \"msg\": \"" + obj.msg + "\", \"name\": \"" + obj.name + "\", \"time\": \"" + getDateTime() …
Run Code Online (Sandbox Code Playgroud)

sockets node.js

5
推荐指数
2
解决办法
1万
查看次数

Java在JFrame上圆角?

我有一个登录JFrame我的应用程序,我想使框架的角落圆几个像素.

我喜欢这样做而不使用JFrame上的透明度并且必须在JPanel中使用背景图像 - 这可能吗?

java swing jframe rounded-corners

5
推荐指数
2
解决办法
1万
查看次数