我有一个 JButton,其背景为绿色,边框为 LineBorder。我想在按钮和边框之间插入一个空格,一种填充。我试过 setMargin(new Insets(x,y,t,z)) 但它似乎不起作用。这是我的一段代码。
JButton JBtn=new JButton("sdfd");
JBtn.setBorder(BorderFactory.createLineBorder(Color.CYAN,5));
JBtn.setBackground(Color.GREEN);
JBtn.setMargin(new Insets(5,5,10,10));
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
我想绘制一个三角形,其顶点在Java Swing中有点平滑.我学会了如何使用这些代码行绘制三角形
Polygon p=new Polygon (vertice_x, vertices_y, number_of_vertices);
g.drawPolygon(p);
Run Code Online (Sandbox Code Playgroud)
但我没有发现圆角.我读过Graphics2D中有一个方法可以让你绘制一个带圆角边框的矩形,但是对于一般的Polygon?我该怎么办?
我上了课
class myClass
{
private:
std::list <myInnerClass> mylists;
class myInnerClass
{
// Design for this private class
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这行std::list <myInnerClass> mylists会给我以下错误:
- Type 'myInnerClass' was not declared in this scope
- Type 'myInnerClass' could not be resolved
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我试图了解使用 common Threads 和Tasks之间的好处。第一个进入System.Threading命名空间,后者进入System.Threading.Tasks命名空间。所以,只是为了玩和熟悉它们,我写了这个程序C#:
class Program
{
static void Main(string[] args)
{
long ticksAtStart = DateTime.UtcNow.Ticks;
new Thread(() => { ExecuteAsyn("Thread", DateTime.UtcNow.Ticks); }).Start();
Console.WriteLine("Using Thread: " + (DateTime.UtcNow.Ticks - ticksAtStart));
ticksAtStart = DateTime.UtcNow.Ticks;
Task g = Task.Factory.StartNew(() => ExecuteAsyn("TPL", DateTime.UtcNow.Ticks));
Console.WriteLine("Using TPL: " + (DateTime.UtcNow.Ticks - ticksAtStart));
g.Wait();
Console.ReadKey();
}
private static void ExecuteAsyn(string source, long ticksAtExecutionTime)
{
Console.WriteLine("Hello World! Using " + source + " the difference between initialization and …Run Code Online (Sandbox Code Playgroud)