小编clo*_*oud的帖子

我怎么能在一个线程中停止块方法DatagramSocket.receive()

DatagramSocket在主线程中创建一个,然后创建一个内部类线程来监听端口.当我DatagramSocket在主线程中关闭时,它总是遇到错误,socket closed因为在内部类线程中我调用了receive()方法,并且它阻塞了内部类线程.这是内部类的代码:

class ReceiveText extends Thread
{
    @Override
    public void run()
    {
        while(true)
        {
            byte[] buffer = new byte[1024];
            DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
            try {
                udpSocket.receive(dp);//blocked here
                byte[] data = dp.getData();
                String message = new String(data, 0 , dp.getLength());
                setTxtAreaShowMessage(message);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在关闭DatagramSocket之前停止内部类线程,但stop()不推荐使用该方法.我怎样才能做到这一点?

java sockets multithreading

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

如何在列表视图中禁用子项(使其颜色变为灰色且不可点击)

在我的应用程序中,有一个列表视图,并单击它的每个项目导致一个操作.

但在某些情况下,某些操作无法完成.

如何禁用列表视图中的子项(使其颜色变为灰色且不可点击)?

android listview

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

如何在C#中启动另一个主要表单

首先,我显示一个登录表单。当用户输入正确的ID和密码时,我想显示另一个表单,然后关闭登录表单。以下是我启动登录表单的方式。

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FrmLogin());
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我想显示主窗体时,我调用该类的dispose()方法FrmLogin,但是应用程序立即结束。我的解决方案是将class 的visible属性更改FrmLoginfalse,我知道这是不对的,请提出解决方案。

c# forms

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

线程中的进度条在主线程中完成工作之前不会更新其UI

我正在将一个大文件切成块,并希望显示进度的速度.当我点击startCut Button时,这里是要执行的代码:

FileInputStream in = new FileInputStream(sourceFile);
int blockSize = (int)(getSelectedBlockSize() * 1024);
int totalBlock = Integer.parseInt(txtNumberOfBlock.getText());
byte[] buffer = new byte[blockSize];
int readBytes = in.read(buffer);
int fileIndex = 1;

class PBThread extends Thread
{
    @Override
    public void run()
    {
        while(true)
        {
            pbCompleteness.setValue(value);
            //value++; //place A
            System.out.println(value);
            if (value >= 100)
                break;
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
        }
    }
}
value = 0;
PBThread pbThread = new PBThread();
pbThread.start();
while(readBytes != -1)
{
    File file …
Run Code Online (Sandbox Code Playgroud)

java swing progress-bar

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

球体纹理映射错误

我使用D3DXCreateSphere方法来创建球体网格.我想在它上面应用地球纹理.我使用以下代码计算像素着色器中的纹理坐标:

sampler ShadeSampler = sampler_state
{
    Texture   = (ShadeTex);
    AddressU = Mirror;
    AddressV = Mirror;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
};
PS_OUTPUT PSMain(VS_OUTPUT input){

PS_OUTPUT output = (PS_OUTPUT)0;

vector uv;

uv.x = 0.5 + atan2(input.normal.z, input.normal.x) / piMul2;
uv.y = 0.5f - asin(input.normal.y) / pi;

vector b = tex2D(ShadeSampler, uv.xy);

output.diffuse = b * input.diffuse;

return output;
}
Run Code Online (Sandbox Code Playgroud)

我使用D3DXCreateTextureFromFileEx方法来创建IDirect3DTexture9,但是当我通过使用参数的D3DX_DEFAULT值启用mipmap功能时MipLevels,渲染结果有点错误,在接缝处总是有一个像素线.下图显示了问题,但是当我通过使用参数D3DX_FROM_FILE值禁用mipmap功能时MipLevels,该行消失.我不知道为什么会这样,有什么建议吗?

在此输入图像描述

directx shader textures texture-mapping

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

无法在JFrame中看到一个组件

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class Box {
    public static void main(String[] args){
        BoxFrame frame = new BoxFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

class BoxFrame extends JFrame{
    public BoxFrame(){
        setTitle("BoxGame");
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        DrawComponent[] component = new DrawComponent[4];
        component[0] = new DrawComponent(0, 0, 20, 20);
        component[1] = new DrawComponent(400, 0, 20, 20);

        add(component[0]);
        add(component[1]);//here the problem is
    }
    public static final int DEFAULT_WIDTH = 600;
    public static final int DEFAULT_HEIGHT = 400;
}

class DrawComponent extends JComponent{
    private double left; …
Run Code Online (Sandbox Code Playgroud)

java jframe

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