我是油漆/图形的新手,并想知道如何将JPanel添加到我的代码中,使得整个图形将在JPanel上,而不是在JFrame上.
换句话说,我正在尝试创建一个允许我这样做的GUI:在右侧显示左侧JPanel 上线条的良好移动,添加一个将显示的JTextArea(在JPanel上)图形的协调.
谢谢!!!
(下图,移动线或只是运行代码)
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import javax.swing.JFrame;
public class Test extends JFrame implements Runnable
{
private Line2D line;
public Test()
{
super("testing");
this.setBounds( 500, 500, 500, 500 );
this.setVisible( true );
}
public void paint( Graphics g )
{
Graphics2D g2 = (Graphics2D) g;
g2.draw(line);
}
@Override
public void run()
{
int x=50;
while (true)
{
try
{
Thread.sleep( 50 );
line = new Line2D.Float(100+x, 100+x, 250-x, 260+x%2);
x++;
repaint(); …Run Code Online (Sandbox Code Playgroud) 我有一个文件夹(MY_FILES),有大约500个文件,每天有一个新文件到达,它放在那里.每个文件的大小约为4Mb.
我刚刚开发了一个简单的'void main'来测试我是否可以在这些文件中搜索特定的通配符.它工作得很好.
问题是我正在删除旧的indexed_folder并重新索引.这需要花费很多时间,显然效率低下.我正在寻找的是"增量索引".意思是,如果索引已经存在 - 只需将新文件添加到索引中.
我想知道Lucene是否有某种机制来检查'doc'是否在尝试索引之前被编入索引.像writer.isDocExists这样的东西?
谢谢!
我的代码看起来像这样:
// build the writer
IndexWriter writer;
IndexWriterConfig indexWriter = new IndexWriterConfig(Version.LUCENE_36, analyzer);
writer = new IndexWriter(fsDir, indexWriter);
writer.deleteAll(); //must - otherwise it will return duplicated result
//build the docs and add to writer
File dir = new File(MY_FILES);
File[] files = dir.listFiles();
int counter = 0;
for (File file : files)
{
String path = file.getCanonicalPath();
FileReader reader = new FileReader(file);
Document doc = new Document();
doc.add(new Field("filename", file.getName(), Field.Store.YES, Field.Index.ANALYZED)); …Run Code Online (Sandbox Code Playgroud) 我刚刚编写了一个简单的python命令来检查csv文件中的大列表.csv有2列,10K行.当我将第二行输入到列表中并稍后打印列表时,IDLE需要相当长的时间才能显示终端(在mac下)及时显示的位置.*BTW,我在两台不同的机器上检查过 - 结果相同.
显然,没有人会在控制台上打印10k项目但是一个比另一个明显更快的想法让我想知道:为什么IDLE应该是python最好的朋友那么慢?
我想打开与mysql数据库的连接并使用不同的查询检索数据.每次获取数据时是否需要关闭连接?还是有更好的方法可以多次查询并仅在结束时关闭连接?
目前我这样做:
db = dbConnect(MySQL(), user='root', password='1234', dbname='my_db', host='localhost')
query1=dbSendQuery(db, "select * from table1")
data1 = fetch(query1, n=10000)
query2=dbSendQuery(db, "select * from table2") ##ERROR !
Run Code Online (Sandbox Code Playgroud)
我收到错误信息:
mysqlExecStatement(conn,statement,...)出错:RS-DBI驱动程序:(与挂起的行连接,在继续之前关闭resultSet)
现在,如果我用dbClearResult(query1)清除结果,我需要重做连接(dbConnect ...)
是否有更好/更有效的方法来获取所有内容而不是每次打开/关闭?
我有以下几点:
fig, ax = plt.subplots(figsize=(40, 10))
sns.lineplot(x="Date", y="KFQ imports", data=df_dry, color="BLACK", ax=ax)
sns.lineplot(x="Date", y="QRR imports", data=df_dry, color="RED",ax=ax)
ax.set(xlabel="Date", ylabel="Value", )
x_dates = df_dry['Date'].dt.strftime('%b-%Y')
ax.set_xticklabels(labels=x_dates, rotation=45)
Run Code Online (Sandbox Code Playgroud)
当我使用条形图 ( sns.barplot) 时,会显示整个日期范围。我是否缺少折线图的某些内容?一世
我正在尝试使用eclipse编写一个带有python的虚拟程序,我收到错误消息:未定义的变量:__init__.
我的目标是用eclipse'Run as' - > Python Run运行程序.
当我删除代码时:
if __init__=='__main__':
main()
Run Code Online (Sandbox Code Playgroud)
并从命令行say_something()运行它 - 它工作正常.知道我做错了什么吗?

我不断收到错误消息:redis.exceptions.ResponseError: NOAUTH Authentication required..(我正在使用 celery 执行后台任务)。
我的 settings.py 如下所示:
CELERY_BROKER_URL = 'redis://user:my_strong_password@'+REDIS_IP+':6379/0'
Run Code Online (Sandbox Code Playgroud)
我有的 docker-compose:
services:
redis:
image: redis:latest
container_name: jh_redis
ports:
- '6379:6379'
command: redis-server --appendonly yes --requirepass my_strong_password
Run Code Online (Sandbox Code Playgroud)
您可以看到我尝试提供的密码(--requirepass)与 settings.py 中显示的完全相同,但是,当 docker 启动并运行时,我仍然收到主题错误消息。
我尝试过不同的组合,例如:
--requirepass 用户:my_strong_password
但还是没用。注意:当我关闭整个命令行时 - 它可以工作(但 32 小时后 - 我收到错误消息并且它停止工作)。
docker-compose 中应该进行哪些适当的设置才能使其顺利工作?
不知道我在这里做错了什么.我的目标是获取方法的注释(如果存在).
public class RunTest
{
public static void main(String[] args) throws Exception, NoSuchMethodException
{
MyAction action = new MyAction();
Method method = action.getClass().getDeclaredMethod("printSomething");
RequiredPermission permission = method.getAnnotation(RequiredPermission.class);
String value = permission.permissionName();
System.out.println("permission name: "+value);
}
}
Run Code Online (Sandbox Code Playgroud)
MyAction类
public class MyAction
{
@RequiredPermission(permissionName="SYSO", permissionValue = 0)
public void printSomething()
{
System.out.println("hi there");
}
public void printABC()
{
System.out.println("ABC...");
}
}
Run Code Online (Sandbox Code Playgroud)
和注释:
public @interface RequiredPermission
{
String permissionName();
int permissionValue();
}
Run Code Online (Sandbox Code Playgroud)
我希望在控制台上看到:
权限名称:SYSO
但相反,我得到:
com.annotation.RunTest.main(RunTest.java:14)中线程"main"java.lang.NullPointerException中的异常
朴素贝叶斯和Logistic回归都可以对这两个数据集进行完美分类吗?我的理解是,朴素贝叶斯(Naive Bayes)可以,带有复杂项的Logistic回归可以对这些数据集进行分类。如果我错了,请帮忙。
数据集的图像在这里:
classification machine-learning dataset data-mining logistic-regression
考虑此代码给出的下图:
require(ggplot2)
my_data<-c(70, 71, 75, 78, 78, 79, 80, 81, 84, 85, 87, 87, 90, 91, 95, 95, 96, 96, 97, 98, 98, 100, 101, 102, 102, 102, 102, 104, 104, 104, 107, 107, 109, 110, 110, 110, 111, 112, 113, 113, 114, 115, 118, 118, 118, 120, 124, 131, 137, 137, 139, 145, 158, 160, 162, 165, 169, 177, 179, 180)
qplot(my_data,dist, geom="line")+xlab("x values")+ylab("Density")+
geom_point()+
ggtitle("cool graph Distribution") +
geom_line(color="black", size=0.1) +
geom_line(stat = "vline", xintercept = "mean", colour …Run Code Online (Sandbox Code Playgroud)