今天我有一个小问题,这可能对于这里的专业人士来说没什么了:)
我希望将我的Swing组件放在一条水平线上.我根据帧大小使用了FlowLayout并更改了componentResized()上组件的大小,但它经常出错(有时候最后一个组件放在下一行)......我决定使用BoxLayout,但是在那段代码上:
down=new JPanel(new BoxLayout(down,BoxLayout.X_AXIS));
down.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
down.add(Box.createHorizontalGlue());
down.setPreferredSize(new Dimension(300,35));
Run Code Online (Sandbox Code Playgroud)
它崩溃了:
Exception in thread "AWT-EventQueue-0" java.awt.AWTError: BoxLayout can't be shared
at javax.swing.BoxLayout.checkContainer(Unknown Source)
at javax.swing.BoxLayout.invalidateLayout(Unknown Source)
at javax.swing.BoxLayout.addLayoutComponent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at ButtonFrame.<init>(chat.java:278)
at chat$1.run(chat.java:20)
aso...
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做,也许我可以让FlowLayout无法制作第二排,或者让盒子布局工作?
谢谢你的回复!
我想知道我是否有2个指针指向相同的对象,然后我使用指针1删除它,它仍然在内存中,指针2将指向null,或者对象将保留在内存中我需要使用删除指针2来免费吗?
我的意思是:
int *p1, *p2;
p1=new int;
p2=p1;
*p1=5;
p2=p1;
delete p1;
int x=*p2;
//Error or x=5?
Run Code Online (Sandbox Code Playgroud) 链接到我的上一个主题: C++类前向声明
现在主要的事情:
我决定将所有返回的类型更改为指针以避免内存泄漏,但现在我得到了:
27 C:\Dev-Cpp\Projektyyy\strategy\Tiles.h ISO C++ forbids declaration of `tile' with no type
27 C:\Dev-Cpp\Projektyyy\strategy\Tiles.h expected `;' before "tick"
Run Code Online (Sandbox Code Playgroud)
它只在基类中,其他一切都没问题... tile类中返回*tile的每个函数都有这个错误...
一些代码:
class tile
{
public:
double health;
tile_type type;
*tile takeDamage(int ammount) {return this;};
*tile onDestroy() {return this;};
*tile onUse() {return this;};
*tile tick() {return this};
virtual void onCreate() {};
};
Run Code Online (Sandbox Code Playgroud) 当我尝试调整列表大小时程序崩溃...看看那个代码,尝试输入1,000,000,000(10 ^ 9)...在我的Windows 7 x64上无法正常工作.
#include <cstdlib>
#include <iostream>
#include <list>
using namespace std;
int main(int argc, char *argv[])
{
list<long long> l;
long long n;
cin>>n;
cout<<l.max_size()<<endl;
//uncomment 1 or 2
//l.resize(n,l.size()+1); //1st try
/*for (long long i=0; i<n; i++) //2nd try
l.push_back(n);*/
//system("PAUSE"); // uncomment if needed
return 0;
}
Run Code Online (Sandbox Code Playgroud)
最大尺寸超过4*10 ^ 9,但仍然无法工作...我使用最新的MinGW(G ++)
我有一个球.我知道它的方位角和速度.我想计算弹跳后的方位角(可能是墙).让我们调用方位角alpha.图片:

我知道阿尔法.我知道墙的方位角.我需要 "?".Beta会很好(但不是那么必要).
我有一条类似的路径:
$path='somefolder/foo/bar/lastdir';
Run Code Online (Sandbox Code Playgroud)
我想删除最后一部分,所以我有:
$path='somefolder/foo/bar';
Run Code Online (Sandbox Code Playgroud)
就像我往上翻了一个文件夹。
我真的是 php 新手,也许它只是一个功能,尽管我在任何地方都找不到。